19 #include "art_root_io/TFileService.h" 73 void runDiagnostics( std::map<
size_t,std::map<size_t,bool> > runToBadChannelMap );
131 std::cout <<
"GoodWireAna Constructor called." <<
std::endl;
162 std::cout <<
"Analyze starting." <<
std::endl;
176 for(
size_t iHit = 0; iHit < hitListHandle->size(); ++iHit ){
189 std::pair<size_t,size_t> CryTPCPair( iCry,iTPC );
208 std::cout <<
"Making histo set." <<
std::endl;
211 std::map< std::pair<size_t,size_t>, std::vector<TH1D*> > outputMap;
214 std::map< std::pair<size_t,size_t>, std::vector<TH1D*> > outputDistMap;
217 for(
size_t iCry = 0; iCry <
fNCry; ++iCry ){
224 for(
size_t iTPC = 0; iTPC < nTPCs; ++iTPC ){
225 std::vector<TH1D*> histoVect;
226 std::vector<TH1D*> histoDistVect;
229 std::pair<size_t,size_t> CryTPCPair(iCry,iTPC);
240 int n = sprintf( name,
"r%d_cry%lu_tpc%lu_U_WireHitOcc", runID, iCry, iTPC);
241 int t = sprintf( title,
";Run %d, Cryostat %lu, TPC %lu, U Plane Wire Hit Occupancies;", runID, iCry, iTPC);
242 TH1D* uHisto =
fTFS->make<TH1D>(
name,
title,nWiresU,0,nWiresU);
243 uHisto->GetXaxis()->SetTitle(
"Wire Index in Plane");
244 uHisto->GetYaxis()->SetTitle(
"Hit Occupancy");
247 n = sprintf( name,
"r%d_cry%lu_tpc%lu_V_WireHitOcc", runID, iCry, iTPC);
248 t = sprintf( title,
";Run %d, Cryostat %lu, TPC %lu, V Plane Wire Hit Occupancies;", runID, iCry, iTPC);
249 TH1D* vHisto =
fTFS->make<TH1D>(
name,
title,nWiresV,0,nWiresV);
250 vHisto->GetXaxis()->SetTitle(
"Wire Index in Plane");
251 vHisto->GetYaxis()->SetTitle(
"Hit Occupancy");
254 n = sprintf( name,
"r%d_cry%lu_tpc%lu_W_WireHitOcc", runID, iCry, iTPC);
255 t = sprintf( title,
";Run %d, Cryostat %lu, TPC %lu, W Plane Wire Hit Occupancies;", runID, iCry, iTPC);
256 TH1D* wHisto =
fTFS->make<TH1D>(
name,
title,nWiresW,0,nWiresW);
257 wHisto->GetXaxis()->SetTitle(
"Wire Index in Plane");
258 wHisto->GetYaxis()->SetTitle(
"Hit Occupancy");
262 histoVect.push_back(uHisto);
263 histoVect.push_back(vHisto);
264 histoVect.push_back(wHisto);
268 n = sprintf( name,
"r%d_cry%lu_tpc%lu_U_HitOccDist", runID, iCry, iTPC);
269 t = sprintf( title,
";Run %d, Cryostat %lu, TPC %lu, U Plane Hit Occupancy Distribution;", runID, iCry, iTPC);
271 uHistoDist->GetXaxis()->SetTitle(
"Hit Occupancy");
272 uHistoDist->GetYaxis()->SetTitle(
"Number of Wires");
275 n = sprintf( name,
"r%d_cry%lu_tpc%lu_V_HitOccDist", runID, iCry, iTPC);
276 t = sprintf( title,
";Run %d, Cryostat %lu, TPC %lu, V Plane Hit Occupancy Distribution;", runID, iCry, iTPC);
278 vHistoDist->GetXaxis()->SetTitle(
"Hit Occupancy");
279 vHistoDist->GetYaxis()->SetTitle(
"Number of Wires");
282 n = sprintf( name,
"r%d_cry%lu_tpc%lu_W_HitOccDist", runID, iCry, iTPC);
283 t = sprintf( title,
";Run %d, Cryostat %lu, TPC %lu, W Plane Hit Occupancy Distribution;", runID, iCry, iTPC);
285 wHistoDist->GetXaxis()->SetTitle(
"Hit Occupancy");
286 wHistoDist->GetYaxis()->SetTitle(
"Number of Wires");
289 histoDistVect.push_back(uHistoDist);
290 histoDistVect.push_back(vHistoDist);
291 histoDistVect.push_back(wHistoDist);
298 outputMap.emplace(CryTPCPair,histoVect);
299 outputDistMap.emplace(CryTPCPair,histoDistVect);
309 std::cout <<
"Done making histo set." <<
std::endl;
318 outfile.open(
"deadWireList.txt");
321 std::cout <<
"Inside writing function." <<
std::endl;
327 int runID = iterRun->first;
328 std::map<std::pair<size_t,size_t>,std::vector<TH1D*> > theCryTPCToPlaneVectMap = iterRun->second;
332 std::cout <<
"runID: " << runID <<
std::endl;
334 for( std::map<std::pair<size_t,size_t>,std::vector<TH1D*> >::
iterator iterCryTPC = theCryTPCToPlaneVectMap.begin(); iterCryTPC != theCryTPCToPlaneVectMap.end(); ++iterCryTPC ){
337 size_t CryID = iterCryTPC->first.first;
338 size_t TPCID = iterCryTPC->first.second;
339 std::vector<TH1D*> planeVect = iterCryTPC->second;
342 std::cout <<
"Cryo/TPC: " << CryID <<
"/" << TPCID <<
std::endl;
346 for(
size_t iPlane = 0; iPlane < planeVect.size(); ++iPlane ){
354 std::cout <<
"PlaneID: " << PlaneID <<
std::endl;
357 TH1D * thisPlaneHist = planeVect.at(iPlane);
360 for(
int iBin = 1; iBin <= thisPlaneHist->GetNbinsX(); ++iBin ){
362 std::cout <<
"BinID: " << iBin <<
", binContent: " << thisPlaneHist->GetBinContent(iBin) <<
std::endl;
366 if( thisPlaneHist->GetBinContent(iBin) == 0 ){
369 std::cout <<
"Inside the final if statement." <<
std::endl;
372 outfile << runID <<
" " << CryID <<
" " << TPCID <<
" " << PlaneID <<
" " << WireID <<
"\n";
407 int runID = iter->first;
410 for( std::map<std::pair<size_t,size_t>,std::vector<TH1D*> >::
iterator iterCryTPC = iter->second.begin(); iterCryTPC != iter->second.end(); ++iterCryTPC ){
413 std::pair<size_t,size_t> CryTPCPair = iterCryTPC->first;
416 std::vector<TH1D*> planeHistos = iterCryTPC->second;
419 for(
size_t iPlane = 0; iPlane < planeHistos.size(); ++iPlane ){
422 size_t repetitionStartWire = 9999;
423 if( iPlane == 0 || iPlane == 1 ){
424 if( CryTPCPair.second % 2 == 0 )
continue;
437 TH1D * thisPlaneHist = planeHistos.at(iPlane);
438 for(
int iBin = 1; iBin <= thisPlaneHist->GetNbinsX(); ++iBin ){
440 if(
size_t(iBin)-1 == repetitionStartWire )
break;
443 std::cout <<
"BinID: " << iBin <<
", binContent: " << thisPlaneHist->GetBinContent(iBin) <<
std::endl;
446 int binContent = thisPlaneHist->GetBinContent(iBin);
459 std::cout <<
"Not filling occupancy distributions with this wire - it's waaaay too big of an outlier on the high side." <<
std::endl;
464 else if( binContent == 0 ){
466 std::cout <<
"Not filling occupancy distributions with this wire - it's waaaay too big of an outlier on the low side." <<
std::endl;
489 int runID = iter->first;
492 for( std::map<std::pair<size_t,size_t>,std::vector<TH1D*> >::
iterator iterCryTPC = iter->second.begin(); iterCryTPC != iter->second.end(); ++iterCryTPC ){
495 std::pair<size_t,size_t> CryTPCPair = iterCryTPC->first;
498 std::vector<TH1D*> planeHistos = iterCryTPC->second;
501 for(
size_t iPlane = 0; iPlane < planeHistos.size(); ++iPlane ){
505 if( CryTPCPair.second % 2 == 0 )
continue;
511 TH1D * thisPlaneHist = planeHistos.at(iPlane);
516 if( thisPlaneHist->Integral() == 0 ){
517 for(
int iBin = 1; iBin <= occupancyHist->GetNbinsX(); ++iBin ){
520 size_t repetitionStartWire = 9999;
525 if( iPlane == 0 || iPlane == 1 ){
526 if(
size_t(iBin)-1 == repetitionStartWire )
break;
532 std::cout <<
"Adding badwirevect to completely dead plane." <<
std::endl;
533 std::vector<size_t> theBadWire;
536 theBadWire.push_back(runID);
537 theBadWire.push_back(CryTPCPair.first);
538 theBadWire.push_back(CryTPCPair.second);
539 theBadWire.push_back(iPlane);
540 theBadWire.push_back(iBin);
541 theBadWire.push_back(0);
544 badWireList.push_back(theBadWire);
552 double gaus_mean = 0;
553 double gaus_sigma = 0;
573 thisPlaneHist->Fit(
"gaus",
"0");
574 TF1* fit1 = (TF1*)thisPlaneHist->GetFunction(
"gaus");
578 gaus_mean = fit1->GetParameter(1);
579 gaus_sigma = fit1->GetParameter(2);
584 std::cout <<
"Fit Parameters, r" << runID <<
"tpc" << CryTPCPair.second <<
"plane" << iPlane <<
": mean: " << gaus_mean <<
", sigma: " << gaus_sigma <<
std::endl;
595 size_t repetitionStartWire = 9999;
596 for(
int iBin = 1; iBin <= occupancyHist->GetNbinsX(); ++iBin ){
604 if( iPlane == 0 || iPlane == 1 ){
605 if(
size_t(iBin)-1 == repetitionStartWire )
break;
632 std::cout <<
"Bin #" << iBin <<
", occupancy: " << occupancyHist->GetBinContent(iBin) <<
std::endl;
639 if( occupancyHist->GetBinContent(iBin) >
fHitOccLimit ){
641 std::cout <<
"Adding badwirevect." <<
std::endl;
642 std::vector<size_t> theBadWire;
645 theBadWire.push_back(runID);
646 theBadWire.push_back(CryTPCPair.first);
647 theBadWire.push_back(CryTPCPair.second);
648 theBadWire.push_back(iPlane);
649 theBadWire.push_back(iBin);
650 theBadWire.push_back(2);
653 badWireList.push_back(theBadWire);
659 else if( occupancyHist->GetBinContent(iBin) == 0 ){
661 std::cout <<
"Adding badwirevect." <<
std::endl;
662 std::vector<size_t> theBadWire;
665 theBadWire.push_back(runID);
666 theBadWire.push_back(CryTPCPair.first);
667 theBadWire.push_back(CryTPCPair.second);
668 theBadWire.push_back(iPlane);
669 theBadWire.push_back(iBin);
670 theBadWire.push_back(0);
673 badWireList.push_back(theBadWire);
676 else if(
float(occupancyHist->GetBinContent(iBin))-(gaus_mean) > gaus_sigma*
fNSigmaGoodWireHigh){
679 std::cout <<
"Adding badwirevect." <<
std::endl;
680 std::vector<size_t> theBadWire;
683 theBadWire.push_back(runID);
684 theBadWire.push_back(CryTPCPair.first);
685 theBadWire.push_back(CryTPCPair.second);
686 theBadWire.push_back(iPlane);
687 theBadWire.push_back(iBin);
690 if(
float(occupancyHist->GetBinContent(iBin)) < gaus_mean ){theBadWire.push_back(1); }
691 else{ theBadWire.push_back(2); }
693 badWireList.push_back(theBadWire);
697 else if(
float(occupancyHist->GetBinContent(iBin)) <
fQuietWireFactor*(gaus_mean) ){
699 std::cout <<
"Adding badwirevect." <<
std::endl;
700 std::vector<size_t> theBadWire;
703 theBadWire.push_back(runID);
704 theBadWire.push_back(CryTPCPair.first);
705 theBadWire.push_back(CryTPCPair.second);
706 theBadWire.push_back(iPlane);
707 theBadWire.push_back(iBin);
708 theBadWire.push_back(1);
709 badWireList.push_back(theBadWire);
713 std::vector<size_t> theGoodWire;
716 theGoodWire.push_back(runID);
717 theGoodWire.push_back(CryTPCPair.first);
718 theGoodWire.push_back(CryTPCPair.second);
719 theGoodWire.push_back(iPlane);
720 theGoodWire.push_back(iBin);
722 goodWireList.push_back(theGoodWire);
725 std::cout <<
"GoodWire run/TPC/Plane/Bin: " << runID <<
"/" << CryTPCPair.second <<
"/" << iPlane <<
"/" << iBin <<
std::endl;
741 outfile.open(
"badChannelList.txt");
746 std::map<size_t,std::vector<size_t> > runToTPCVectMapNoisy;
747 std::map<size_t,std::vector<size_t> > runToTPCVectMapQuiet;
748 std::map<size_t,std::vector<size_t> > runToTPCVectMapDead;
751 std::vector<size_t> tempVect;
755 for(
size_t iQ = 0; iQ < nTPCs ; ++iQ ){
756 tempVect.push_back(0);
761 std::cout <<
"Size of badwirevect: " << badWireVect.size() <<
std::endl;
762 for(
size_t iWire = 0; iWire < badWireVect.size(); ++iWire ){
765 if( badWireVect.at(iWire).at(3) != 2 )
continue;
769 size_t runID = badWireVect.at(iWire).at(0);
773 if( runToTPCVectMapNoisy.count(runID) == 0 ){
774 runToTPCVectMapNoisy.emplace(runID,tempVect);
775 runToTPCVectMapQuiet.emplace(runID,tempVect);
776 runToTPCVectMapDead.emplace(runID,tempVect);
780 size_t type = badWireVect.at(iWire).at(5);
781 size_t tpc = badWireVect.at(iWire).at(2);
783 runToTPCVectMapDead.at(runID).at(tpc)++;
786 runToTPCVectMapQuiet.at(runID).at(tpc)++;
789 runToTPCVectMapNoisy.at(runID).at(tpc)++;
806 geo::WireID theWireID( badWireVect.at(iWire).at(1), badWireVect.at(iWire).at(2), badWireVect.at(iWire).at(3),badWireVect.at(iWire).at(4)-1);
808 std::cout <<
"We're in plane: " << badWireVect.at(iWire).at(3) <<
", and wire: " << theWireID.Wire <<
" corresponds to channel: " << channel <<
std::endl;
811 std::cout <<
"Cryo/TPC/Plane/Wire/Channel: " << badWireVect.at(iWire).at(1) <<
"/" << badWireVect.at(iWire).at(2) <<
"/" << badWireVect.at(iWire).at(3) <<
"/" << badWireVect.at(iWire).at(4)-1 <<
"/" << channel <<
std::endl;
814 outfile << badWireVect.at(iWire).at(0) <<
" " << channel <<
" " << badWireVect.at(iWire).at(5) <<
" " << badWireVect.at(iWire).at(2) <<
" " << badWireVect.at(iWire).at(3) <<
" " << badWireVect.at(iWire).at(4) <<
"\n";
823 std::cout <<
"********************************************************" <<
std::endl;
824 std::cout <<
"*************** JOB SUMMARY OF BAD WIRES ***************" <<
std::endl;
825 std::cout <<
"********************************************************" <<
std::endl;
827 std::cout <<
"Note: Collection plane only at the moment." <<
std::endl;
830 for( std::map<
size_t,std::vector<size_t> >::
iterator runIter = runToTPCVectMapNoisy.begin(); runIter != runToTPCVectMapNoisy.end(); ++runIter ){
831 size_t runID = runIter->first;
832 std::cout <<
"\n **** RUN #" << runID <<
" SUMMARY **** " <<
std::endl;
835 for(
size_t iTPC = 0; iTPC < nTPCs; ++iTPC ){
836 std::cout <<
"Number of noisy wires in TPC #" << iTPC <<
": " << runToTPCVectMapNoisy.at(runID).at(iTPC) <<
std::endl;
837 std::cout <<
"Number of quiet wires in TPC #" << iTPC <<
": " << runToTPCVectMapQuiet.at(runID).at(iTPC) <<
std::endl;
838 std::cout <<
"Number of dead wires in TPC #" << iTPC <<
": " << runToTPCVectMapDead.at(runID).at(iTPC) <<
std::endl;
858 std::map<size_t,float> runToDayCount;
859 runToDayCount.emplace(15651, 0);
860 runToDayCount.emplace(15652, 0.0048);
861 runToDayCount.emplace(15653, 0.0069);
862 runToDayCount.emplace(15654, 0.01);
863 runToDayCount.emplace(15655, 0.011);
864 runToDayCount.emplace(15864, 0.98);
865 runToDayCount.emplace(15865, 0.984);
866 runToDayCount.emplace(15866, 0.99);
867 runToDayCount.emplace(16488, 4.501);
868 runToDayCount.emplace(16489, 4.502);
871 std::vector<float> badChannelCounts;
872 std::vector<float> timeInDays;
875 for( std::map<
size_t,std::map<size_t,bool> >::
iterator iter = runToBadChannelMap.begin(); iter != runToBadChannelMap.end(); iter++ ){
876 badChannelCounts.push_back(iter->second.size());
877 timeInDays.push_back(runToDayCount.at(iter->first));
900 outfile.open(
"goodChannelList.txt");
907 std::cout <<
"Size of goodwirevect: " << goodWireVect.size() <<
std::endl;
908 for(
size_t iWire = 0; iWire < goodWireVect.size(); ++iWire ){
911 if( goodWireVect.at(iWire).at(3) != 2 )
continue;
918 geo::WireID theWireID( goodWireVect.at(iWire).at(1), goodWireVect.at(iWire).at(2), goodWireVect.at(iWire).at(3),goodWireVect.at(iWire).at(4)-1);
922 std::cout <<
"Cryo/TPC/Plane/Wire/Channel: " << goodWireVect.at(iWire).at(1) <<
"/" << goodWireVect.at(iWire).at(2) <<
"/" << goodWireVect.at(iWire).at(3) <<
"/" << goodWireVect.at(iWire).at(4)-1 <<
"/" << channel <<
std::endl;
925 outfile << goodWireVect.at(iWire).at(0) <<
" " << channel <<
std::endl;
933 std::cout <<
"NumGood: " << numGood <<
std::endl;
949 for(
size_t iTPC = 0; iTPC < nTPCs; ++iTPC ){
952 for(
size_t iPlane = 0; iPlane < nPlanes; ++iPlane ){
955 if( iPlane == 2 )
continue;
956 std::map<size_t,size_t> tempMap;
957 size_t theFinalWire = 0;
960 for(
size_t iWire = 0; iWire <
fGeometry->
Nwires(iPlane,iTPC,iCry); ++iWire ){
963 geo::WireID theWireID( iCry, iTPC, iPlane, iWire );
969 if( tempMap.count(channel) == 1 ){
970 theFinalWire = iWire;
975 tempMap.emplace(channel,
true);
986 std::cout <<
"TheFinalWire: TPC/Plane/Wire: " << iTPC <<
"/" << iPlane <<
"/" << theFinalWire <<
std::endl;
1000 std::cout <<
"GoodWireAna beginJob called." <<
std::endl;
1020 std::cout <<
"GoodWireAna beginRun called." <<
std::endl;
1037 std::cout <<
"EndJob reached." <<
std::endl;
1039 std::cout <<
"EndJob Reached." <<
std::endl;
1043 std::vector<std::vector<size_t> > badWireVect;
1044 std::vector<std::vector<size_t> > goodWireVect;
1056 std::cout <<
"Writing Bad." <<
std::endl;
1061 std::cout <<
"Writing Good." <<
std::endl;
1099 std::cout <<
"NSigmaGoodWireHigh/Low: " << fNSigmaGoodWireHigh <<
"/" << fNSigmaGoodWireLow <<
std::endl;
void beginRun(art::Run const &r) override
void endSubRun(art::SubRun const &sr) override
void respondToCloseOutputFiles(art::FileBlock const &fb) override
void respondToOpenInputFile(art::FileBlock const &fb) override
Handle< PROD > getHandle(SelectorBase const &) const
geo::WireID WireID() const
CryostatID_t Cryostat
Index of cryostat.
void writeListOfBadWires(std::vector< std::vector< size_t > > badWireVect)
void reconfigure(fhicl::ParameterSet const &p)
WireID_t Wire
Index of the wire within its plane.
size_t fHitLimitPerWirePerEventOddTPC
std::map< size_t, size_t > fVPlaneRepeatingWireStart
EDAnalyzer(fhicl::ParameterSet const &pset)
unsigned int Ncryostats() const
Returns the number of cryostats in the detector.
unsigned int Nwires(unsigned int p, unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wires in the specified plane.
void runDiagnostics(std::map< size_t, std::map< size_t, bool > > runToBadChannelMap)
std::map< size_t, size_t > fUPlaneRepeatingWireStart
art framework interface to geometry description
bool fOnlyWriteCollectionPlane
void respondToOpenOutputFiles(art::FileBlock const &fb) override
void fitHitOccDistHists(std::vector< std::vector< size_t > > &badWireList, std::vector< std::vector< size_t > > &goodWireList)
#define DEFINE_ART_MODULE(klass)
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
geo::Geometry * fGeometry
pointer to the Geometry service
T get(std::string const &key) const
void findRepeatingWireCutoff()
The geometry of one entire detector, as served by art.
PlaneID_t Plane
Index of the plane within its TPC.
GoodWireAna(fhicl::ParameterSet const &p)
Encapsulate the geometry of a wire.
unsigned int NTPC(unsigned int cstat=0) const
Returns the total number of TPCs in the specified cryostat.
void analyze(art::Event const &e) override
void fillHitOccDistHists(std::vector< std::vector< size_t > > &badWireVect)
float fNSigmaGoodWireHigh
raw::ChannelID_t PlaneWireToChannel(WireID const &wireid) const
Returns the ID of the TPC channel connected to the specified wire.
void makeHistoSetForThisRun(int runID)
Declaration of signal hit object.
size_t fHitLimitPerWirePerEventEvenTPC
Encapsulate the construction of a single detector plane.
GoodWireAna & operator=(GoodWireAna const &)=delete
void respondToCloseInputFile(art::FileBlock const &fb) override
detail::Node< FrameID, bool > PlaneID
std::map< int, std::map< std::pair< size_t, size_t >, std::vector< TH1D * > > > fRunToCryTPCToPlaneMapDist
IDparameter< geo::TPCID > TPCID
Member type of validated geo::TPCID parameter.
2D representation of charge deposited in the TDC/wire plane
void writeListOfDeadWires()
std::map< int, size_t > fNEvtsPerRun
TPCID_t TPC
Index of the TPC within its cryostat.
static constexpr double sr
void beginSubRun(art::SubRun const &sr) override
std::map< int, std::map< std::pair< size_t, size_t >, std::vector< TH1D * > > > fRunToCryTPCToPlaneMap
void writeListOfGoodWires(std::vector< std::vector< size_t > > goodWireVect)
QTextStream & endl(QTextStream &s)
void endRun(art::Run const &r) override
std::string fHitModuleLabel