37 #include "art_root_io/TFileDirectory.h" 38 #include "art_root_io/TFileService.h" 41 #include "canvas/Persistency/Common/FindMany.h" 42 #include "canvas/Persistency/Common/FindManyP.h" 48 enum PType{
kUnknown=0,
kMarl,
kAPA,
kCPA,
kAr39,
kAr42,
kNeutron,
kKryp,
kPlon,
kRdon,
kNPTypes };
73 void FillMyMaps ( std::map< int, simb::MCParticle> &MyMap,
74 art::FindManyP<simb::MCParticle> Assn,
76 std::map<int, int>* indexMap=
nullptr);
79 bool InMyMap (
int TrID, std::map< int, simb::MCParticle> ParMap );
80 void CalcAdjHits ( std::vector< recob::Hit > MyVec, TH1I* MyHist,
bool HeavDebug=
"false" );
248 fDAQSimTree = tfs->make<TTree>(
"DAQSimTree",
"DAQ simulation analysis tree");
290 hAdjHits_Marl = tfs->make<TH1I>(
"hAdjHits_Marl",
"Number of adjacent collection plane hits for MARLEY; Number of adjacent collection plane hits; Number of events" , 21, -0.5, 20.5 );
291 hAdjHits_APA = tfs->make<TH1I>(
"hAdjHits_APA" ,
"Number of adjacent collection plane hits for APAs; Number of adjacent collection plane hits; Number of events" , 21, -0.5, 20.5 );
292 hAdjHits_CPA = tfs->make<TH1I>(
"hAdjHits_CPA" ,
"Number of adjacent collection plane hits for CPAs; Number of adjacent collection plane hits; Number of events" , 21, -0.5, 20.5 );
293 hAdjHits_Ar39 = tfs->make<TH1I>(
"hAdjHits_Ar39",
"Number of adjacent collection plane hits for Argon39; Number of adjacent collection plane hits; Number of events" , 21, -0.5, 20.5 );
294 hAdjHits_Ar42 = tfs->make<TH1I>(
"hAdjHits_Ar42",
"Number of adjacent collection plane hits for Argon42; Number of adjacent collection plane hits; Number of events" , 21, -0.5, 20.5 );
295 hAdjHits_Neut = tfs->make<TH1I>(
"hAdjHits_Neut",
"Number of adjacent collection plane hits for Neutrons; Number of adjacent collection plane hits; Number of events", 21, -0.5, 20.5 );
296 hAdjHits_Kryp = tfs->make<TH1I>(
"hAdjHits_Kryp",
"Number of adjacent collection plane hits for Krypton; Number of adjacent collection plane hits; Number of events" , 21, -0.5, 20.5 );
297 hAdjHits_Plon = tfs->make<TH1I>(
"hAdjHits_Plon",
"Number of adjacent collection plane hits for Polonium; Number of adjacent collection plane hits; Number of events", 21, -0.5, 20.5 );
298 hAdjHits_Rdon = tfs->make<TH1I>(
"hAdjHits_Rdon",
"Number of adjacent collection plane hits for Radon; Number of adjacent collection plane hits; Number of events" , 21, -0.5, 20.5 );
299 hAdjHits_Oth = tfs->make<TH1I>(
"hAdjHits_Oth" ,
"Number of adjacent collection plane hits for Others; Number of adjacent collection plane hits; Number of events" , 21, -0.5, 20.5 );
306 art::FindMany<simb::MCTruth> assn(allParticles,evt,
fGEANTLabel);
307 std::map<int, const simb::MCTruth*> idToTruth;
308 for(
size_t i=0; i<allParticles->size(); ++i){
310 const std::vector<const simb::MCTruth*> truths=assn.at(i);
311 if(truths.size()==1){
312 idToTruth[particle.
TrackId()]=truths[0];
315 mf::LogDebug(
"DAQSimAna") <<
"Particle " << particle.
TrackId() <<
" has " << truths.size() <<
" truths";
316 idToTruth[particle.
TrackId()]=
nullptr;
321 auto& simchs=*evt.
getValidHandle<std::vector<sim::SimChannel>>(
"largeant");
323 for(
auto&& simch: simchs){
332 std::vector<std::vector<std::pair<int, const sim::IDE*> > > contigIDEs;
334 for (
const auto& TDCinfo: simch.TDCIDEMap()) {
338 if(contigIDEs.empty() || TDCinfo.first-prevTDC>5){
339 contigIDEs.push_back(
std::vector<std::pair<int, const sim::IDE*> >());
341 std::vector<std::pair<int, const sim::IDE*> >& currentIDEs=contigIDEs.back();
344 for (
const sim::IDE& ide: TDCinfo.second) {
345 currentIDEs.push_back(std::make_pair(TDCinfo.first, &ide));
347 prevTDC=TDCinfo.first;
350 for(
auto const& contigs : contigIDEs){
355 std::map<PType, float> ptypeToEnergy;
356 for(
auto const& timeide : contigs){
357 const int tdc=timeide.first;
360 const sim::IDE& ide=*timeide.second;
361 const float thisEnergy=ide.
energy;
365 ptypeToEnergy[thisPType]+=thisEnergy;
369 for(
auto const& it : ptypeToEnergy){
370 if(it.second>bestEnergy){
371 bestEnergy=it.second;
408 std::cout <<
"MarlTrue.size()=" << MarlTrue->size() <<
std::endl;
409 art::FindManyP<simb::MCParticle> MarlAssn(MarlTrue,evt,
fGEANTLabel);
416 art::FindManyP<simb::MCParticle> APAAssn(APATrue,evt,
fGEANTLabel);
423 art::FindManyP<simb::MCParticle> CPAAssn(CPATrue,evt,
fGEANTLabel);
430 art::FindManyP<simb::MCParticle> Ar39Assn(Ar39True,evt,
fGEANTLabel);
437 art::FindManyP<simb::MCParticle> Ar42Assn(Ar42True,evt,
fGEANTLabel);
444 art::FindManyP<simb::MCParticle> NeutAssn(NeutTrue,evt,
fGEANTLabel);
451 art::FindManyP<simb::MCParticle> KrypAssn(KrypTrue,evt,
fGEANTLabel);
458 art::FindManyP<simb::MCParticle> PlonAssn(PlonTrue,evt,
fGEANTLabel);
465 art::FindManyP<simb::MCParticle> RdonAssn(RdonTrue,evt,
fGEANTLabel);
470 std::map<PType, std::map< int, simb::MCParticle >&> PTypeToMap{
482 for(
auto const& it : PTypeToMap){
487 auto const&
m=it.second;
488 for(
auto const& it2 : m){
495 mf::LogDebug(
"DAQSimAna") <<
"There are a total of " << PartList.size() <<
" MCParticles in the event ";
500 std::vector< recob::Hit > ColHits_Marl;
501 std::vector< recob::Hit > ColHits_CPA;
502 std::vector< recob::Hit > ColHits_APA;
503 std::vector< recob::Hit > ColHits_Ar39;
504 std::vector< recob::Hit > ColHits_Ar42;
505 std::vector< recob::Hit > ColHits_Neut;
506 std::vector< recob::Hit > ColHits_Kryp;
507 std::vector< recob::Hit > ColHits_Plon;
508 std::vector< recob::Hit > ColHits_Rdon;
509 std::vector< recob::Hit > ColHits_Oth;
523 double TopEFrac = -DBL_MAX;
529 const double start = ThisHit.
PeakTime()-20;
534 for (
size_t ideL=0; ideL < ThisHitIDE.size(); ++ideL) {
535 if ( ThisHitIDE[ideL].energyFrac > TopEFrac ) {
536 TopEFrac = ThisHitIDE[ideL].energyFrac;
537 MainTrID = ThisHitIDE[ideL].trackID;
542 int thisMarleyIndex=-1;
543 if(ThisPType==
kMarl){
546 std::cout <<
"Track ID " << MainTrID <<
" is not in Marley index map" <<
std::endl;
549 thisMarleyIndex=it->second;
579 if (ThisHit.
View() == 2) {
580 if (ThisPType ==
kUnknown) ColHits_Oth .push_back( ThisHit );
581 else if (ThisPType ==
kMarl) ColHits_Marl.push_back( ThisHit );
582 else if (ThisPType ==
kAPA) ColHits_APA .push_back( ThisHit );
583 else if (ThisPType ==
kCPA) ColHits_CPA .push_back( ThisHit );
584 else if (ThisPType ==
kAr39) ColHits_Ar39.push_back( ThisHit );
585 else if (ThisPType ==
kAr42) ColHits_Ar42.push_back( ThisHit );
586 else if (ThisPType ==
kNeutron) ColHits_Neut.push_back( ThisHit );
587 else if (ThisPType ==
kKryp) ColHits_Kryp.push_back( ThisHit );
588 else if (ThisPType ==
kPlon) ColHits_Plon.push_back( ThisHit );
589 else if (ThisPType ==
kRdon) ColHits_Rdon.push_back( ThisHit );
594 mf::LogDebug(
"DAQSimAna") <<
"\n\nAfter all of that I have a total of " << ColHits_Marl.size() <<
" MARLEY col plane hits.";
595 for (
size_t hh=0; hh<ColHits_Marl.size(); ++hh) {
596 mf::LogDebug(
"DAQSimAna") <<
"\tHit " << hh <<
" was on chan " << ColHits_Marl[hh].Channel() <<
" at " << ColHits_Marl[hh].PeakTime();
601 mf::LogDebug(
"DAQSimAna") <<
"\nAnd now for APA hits...";
603 mf::LogDebug(
"DAQSimAna") <<
"\nAnd now for CPA hits...";
605 mf::LogDebug(
"DAQSimAna") <<
"\nAnd now for Ar39 hits...";
607 mf::LogDebug(
"DAQSimAna") <<
"\nAnd now for Ar42 hits...";
609 mf::LogDebug(
"DAQSimAna") <<
"\nAnd now for Neuton hits...";
611 mf::LogDebug(
"DAQSimAna") <<
"\nAnd now for Krypton hits...";
613 mf::LogDebug(
"DAQSimAna") <<
"\nAnd now for Polonium hits...";
615 mf::LogDebug(
"DAQSimAna") <<
"\nAnd now for Radon hits...";
617 mf::LogDebug(
"DAQSimAna") <<
"\nAnd now for Other hits...";
628 std::map<int, int>* indexMap)
630 for (
size_t L1=0; L1 < Hand->size(); ++L1 ) {
631 for (
size_t L2=0; L2 < Assn.at(L1).size(); ++L2 ) {
633 MyMap[ThisPar.
TrackId()] = ThisPar;
634 if(indexMap) indexMap->insert({ThisPar.
TrackId(), L1});
646 ThisPType=it->second;
649 std::cout <<
"In WhichParType, ptype is " << (
int)ThisPType <<
std::endl;
674 ParIt = ParMap.find( TrID );
675 if ( ParIt != ParMap.end() ) {
683 const double TimeRange = 20;
684 const int ChanRange = 2;
685 unsigned int FilledHits = 0;
686 unsigned int NumOriHits = MyVec.size();
687 while( NumOriHits != FilledHits ) {
688 if (HeavDebug)
mf::LogDebug(
"DAQSimAna") <<
"\nStart of my while loop";
689 std::vector< recob::Hit > AdjHitVec;
690 AdjHitVec.push_back ( MyVec[0] );
691 MyVec.erase( MyVec.begin()+0 );
693 int NewSize = AdjHitVec.size();
694 while ( LastSize != NewSize ) {
695 std::vector<int> AddNow;
696 for (
size_t aL=0; aL < AdjHitVec.size(); ++aL) {
697 for (
size_t nL=0; nL < MyVec.size(); ++nL) {
699 mf::LogDebug(
"DAQSimAna") <<
"\t\tLooping though AdjVec " << aL <<
" and MyVec " << nL
700 <<
" AdjHitVec - " << AdjHitVec[aL].Channel() <<
" & " << AdjHitVec[aL].PeakTime()
701 <<
" MVec - " << MyVec[nL].Channel() <<
" & " << MyVec[nL].PeakTime()
702 <<
" Channel " <<
abs( (
int)AdjHitVec[aL].Channel() - (
int)MyVec[nL].Channel() ) <<
" bool " << (
bool)(
abs( (
int)AdjHitVec[aL].Channel() - (
int)MyVec[nL].Channel() ) <= ChanRange)
703 <<
" Time " <<
abs( AdjHitVec[aL].PeakTime() - MyVec[nL].PeakTime() ) <<
" bool " << (
bool)(
abs( (
double)AdjHitVec[aL].PeakTime() - (
double)MyVec[nL].PeakTime() ) <= TimeRange);
706 if (
abs( (
int)AdjHitVec[aL].Channel() - (
int)MyVec[nL].Channel() ) <= ChanRange &&
707 abs( (
double)AdjHitVec[aL].PeakTime() - (
double)MyVec[nL].PeakTime() ) <= TimeRange ) {
708 if (HeavDebug)
mf::LogDebug(
"DAQSimAna") <<
"\t\t\tFound a new thing!!!";
710 bool AlreadyPres =
false;
711 for (
size_t zz=0; zz<AddNow.size(); ++zz) {
712 if (AddNow[zz] == (
int)nL) AlreadyPres =
true;
715 AddNow.push_back( nL );
720 for (
size_t aa=0; aa<AddNow.size(); ++aa) {
722 mf::LogDebug(
"DAQSimAna") <<
"\tRemoving element " << AddNow.size()-1-aa <<
" from MyVec ===> " 723 << MyVec[ AddNow[AddNow.size()-1-aa] ].Channel() <<
" & " << MyVec[ AddNow[AddNow.size()-1-aa] ].PeakTime();
726 AdjHitVec.push_back ( MyVec[ AddNow[AddNow.size()-1-aa] ] );
727 MyVec.erase( MyVec.begin() + AddNow[AddNow.size()-1-aa] );
730 NewSize = AdjHitVec.size();
732 mf::LogDebug(
"DAQSimAna") <<
"\t---After that pass, AddNow was size " << AddNow.size() <<
" ==> LastSize is " << LastSize <<
", and NewSize is " << NewSize
733 <<
"\nLets see what is in AdjHitVec....";
734 for (
size_t aL=0; aL < AdjHitVec.size(); ++aL) {
735 mf::LogDebug(
"DAQSimAna") <<
"\tElement " << aL <<
" is ===> " << AdjHitVec[aL].Channel() <<
" & " << AdjHitVec[aL].PeakTime();
740 int NumAdjColHits = AdjHitVec.size();
741 if (HeavDebug)
mf::LogDebug(
"DAQSimAna") <<
"After that loop, I had " << NumAdjColHits <<
" adjacent collection plane hits.";
742 MyHist -> Fill( NumAdjColHits );
743 FilledHits += NumAdjColHits;
TrackID_t trackID
Geant4 supplied track ID.
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
std::vector< int > GenType
The generator which generated the particle responsible for the hit.
EventNumber_t event() const
art::ServiceHandle< cheat::BackTrackerService > bt_serv
void CalcAdjHits(std::vector< recob::Hit > MyVec, TH1I *MyHist, bool HeavDebug="false")
std::vector< int > HitChan
The channel which the hit occurs on.
std::map< int, int > trkIDToMarleyIndex
std::string fRawDigitLabel
std::vector< int > IDEEndTime
geo::WireID WireID() const
float RMS() const
RMS of the hit shape, in tick units.
std::map< int, PType > trkIDToPType
std::vector< int > IDEStartTime
std::map< int, simb::MCParticle > PlonParts
float Integral() const
Integral under the calibrated signal waveform of the hit, in tick x ADC units.
geo::View_t View() const
View for the plane of the hit.
std::vector< int > IDEParticle
EDAnalyzer(fhicl::ParameterSet const &pset)
DAQSimAna(fhicl::ParameterSet const &p)
std::map< int, simb::MCParticle > CPAParts
void FillMyMaps(std::map< int, simb::MCParticle > &MyMap, art::FindManyP< simb::MCParticle > Assn, art::ValidHandle< std::vector< simb::MCTruth > > Hand, std::map< int, int > *indexMap=nullptr)
art framework interface to geometry description
std::vector< int > IDEChannel
float PeakAmplitude() const
The estimated amplitude of the hit at its peak, in ADC units.
std::vector< int > HitSize
Time width (ticks) Start - End time.
std::map< int, simb::MCParticle > NeutParts
std::map< int, simb::MCParticle > KrypParts
std::map< int, simb::MCParticle > Ar42Parts
#define DEFINE_ART_MODULE(klass)
DAQSimAna & operator=(DAQSimAna const &)=delete
Ionization at a point of the TPC sensitive volume.
T get(std::string const &key) const
float energy
energy deposited by ionization by this track ID and time [MeV]
std::vector< float > IDEEnergy
Provenance const * provenance() const
std::map< int, simb::MCParticle > APAParts
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
SubRunNumber_t subRun() const
static int max(int a, int b)
raw::TDCtick_t StartTick() const
Initial tdc tick for hit.
std::vector< int > MarleyIndex
Which SN in the list of Marley interactions this hit is from (-1 if not from SN)
bool InMyMap(int TrID, std::map< int, simb::MCParticle > ParMap)
Detector simulation of raw signals on wires.
const sim::ParticleList & ParticleList() const
void SaveIDEs(art::Event const &evt)
raw::TDCtick_t EndTick() const
Final tdc tick for hit.
std::map< int, simb::MCParticle > MarlParts
std::map< int, simb::MCParticle > Ar39Parts
std::vector< float > HitPeak
The peak ADC value of the hit.
float PeakTime() const
Time of the signal peak, in tick units.
Declaration of signal hit object.
std::vector< float > HitTime
The time of the hit (ticks)
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
art::ServiceHandle< cheat::ParticleInventoryService > pi_serv
std::vector< float > HitInt
The ADC integral of the hit.
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
float SummedADC() const
The sum of calibrated ADC counts of the hit (0. by default)
std::map< int, simb::MCParticle > RdonParts
std::vector< float > HitRMS
The RMS of the hit.
void reconfigure(fhicl::ParameterSet const &p)
2D representation of charge deposited in the TDC/wire plane
Tools and modules for checking out the basics of the Monte Carlo.
std::vector< float > HitSADC
The summed ADC of the hit.
TPCID_t TPC
Index of the TPC within its cryostat.
LArSoft geometry interface.
raw::ChannelID_t Channel() const
ID of the readout channel the hit was extracted from.
art::ServiceHandle< geo::Geometry > geo
std::vector< float > IDEElectrons
PType WhichParType(int TrID)
std::vector< int > HitTPC
The TPC which the hit occurs in.
std::vector< sim::TrackIDE > ChannelToTrackIDEs(detinfo::DetectorClocksData const &clockData, raw::ChannelID_t channel, const double hit_start_time, const double hit_end_time) const
std::vector< int > HitView
View i.e Coll, U, V.
float numElectrons
number of electrons at the readout for this track ID and time
QTextStream & endl(QTextStream &s)
Signal from collection planes.
void analyze(art::Event const &evt) override