33 #include "Utilities/func/MathUtil.h" 34 #include "NovaDAQConventions/DAQConventions.h" 35 #include "DAQDataFormats/NanoSliceVersionConvention.h" 43 #include "TLorentzVector.h" 124 TVector3 *
vtx=
new TVector3(0,0,0);
163 produces< std::vector<rb::Cluster> >();
164 produces<std::vector<rawdata::RawDigit> >();
179 fTree = tfs->
make<TTree>(
"brem",
"brem");
180 fTree->Branch(
"run", &
run,
"run/I");
192 fTree->Branch(
"vtx",
"TVector3", &
vtx);
212 fHNTrk = tfs->
make<TH1F>(
"hNTrk",
"", 100, 0, 100);
214 fHCosZ = tfs->
make<TH1F>(
"hCosZ",
"", 200, -1, 1);
215 for(
int i=0;
i<5;
i++)
217 fHNPlane = tfs->
make<TH1F>(
"hNPlane",
"", 1000, 0, 1000);
221 fHEdep = tfs->
make<TH1F>(
"hEdep",
"", 1000, 0, 1);
222 fHADC = tfs->
make<TH1F>(
"hADC",
"", 1000, 0, 1000);
223 fHPE = tfs->
make<TH1F>(
"hPE",
"", 1000, 0, 1000);
224 fHPECorr = tfs->
make<TH1F>(
"hPECorr",
"", 1000, 0, 1000);
228 fHHitMap = tfs->
make<TH2F>(
"hHitMap",
"", 200, 0, 200, 400, 0, 400);
229 fHHitMapRW = tfs->
make<TH2F>(
"hHitMapRW",
"", 200, 0, 200, 400, 0, 400);
278 std::vector< rawdata::RawDigit> newDigits;
279 newDigits.reserve(cellhit->size());
286 std::unique_ptr< std::vector<rawdata::RawDigit> > showerDigits(
new std::vector<rawdata::RawDigit>);
289 std::unique_ptr< std::vector<rb::Cluster> > showercol(
new std::vector<rb::Cluster>);
298 fHNTrk->Fill(trackcol->size());
301 std::vector<rb::WeightedHit > trackHits;
304 for(
unsigned int iSlice = 0; iSlice < slicecol->size(); ++iSlice) {
308 bool goodSlice =
true;
309 if (slc->
NCell() <= 0)
continue;
310 if(slc->
MeanTNS () <25000 || slc->
MeanTNS () > 475000) {goodSlice =
false;}
312 std::vector< art::Ptr<rb::Track> > tracks = fmt.at(iSlice);
322 bool isShower =
false;
323 bool isCandTrack =
false;
327 if(!slc->
IsNoise() && tracks.size()==1 && tracks[0]->Is3D() && goodSlice){
329 bool startContained =
false;
330 bool endContained =
false;
347 else nPlaneTrack = tracks[0]->MaxPlane() - tracks[0]->MinPlane();
349 cosz = tracks[0]->Dir().Z();
351 if(startContained) isCandTrack =
false;
358 if(nPlaneTrack<
fPlaneCut) isCandTrack =
false;
391 if(!startContained && endContained &&
startPlane>0 &&
endPlane>0) {isShower =
true; isDiF =
true;}
416 else maxPlane = tracks[0]->MaxPlane();
425 int nTrajPt = tracks[0]->NTrajectoryPoints();
427 for(
int iTraj = 0 ; iTraj < nTrajPt ; iTraj++ ){
429 if( startPoint.Z()-3.3 < tracks[0]->TrajectoryPoint(iTraj).Z() &&
430 startPoint.Z()+3.3 > tracks[0]->TrajectoryPoint(iTraj).Z()){
431 vtx->SetXYZ(tracks[0]->TrajectoryPoint(iTraj).
X(),
432 tracks[0]->TrajectoryPoint(iTraj).
Y(),
433 tracks[0]->TrajectoryPoint(iTraj).
Z());
441 for(
int iPlane=minPlane; iPlane<=
maxPlane; iPlane++){
442 std::vector< art::Ptr<rb::CellHit> > planeHits;
445 unsigned int cellClose1=0;
446 unsigned int cellClose2=0;
447 double cellCloseDist1=10000000;
448 double cellCloseDist2=10000000;
449 double edepClose1 = 0;
450 double edepClose2 = 0;
481 double mipDeDx = 0.00157;
487 for(
unsigned int iCell=0; iCell<tracks[0]->NCell(); ++iCell){
492 if(chit->
Plane() != iPlane)
continue;
493 planeHits.push_back(tracks[0]->Cell(iCell));
497 geom->
Plane( chit->
Plane() )->Cell( chit->
Cell() )->GetCenter(xyz);
500 double cellXY, trackStartXY;
501 double cellZ = xyz[2];
502 double trackStartZ = tracks[0]->Start().Z();
503 double slope = tracks[0]->Dir().X()/tracks[0]->Dir().Z();
507 trackStartXY = tracks[0]->Start().X();
508 slope = tracks[0]->Dir().X()/tracks[0]->Dir().Z();
512 trackStartXY = tracks[0]->Start().Y();
513 slope = tracks[0]->Dir().Y()/tracks[0]->Dir().Z();
516 double cellDist =
fabs(cellXY - trackStartXY - slope*(cellZ - trackStartZ));
520 if(cellDist<cellCloseDist1){
521 cellCloseDist2 = cellCloseDist1;
522 cellClose2 = cellClose1;
523 edepClose2 = edepClose1;
524 cellCloseDist1 = cellDist;
525 cellClose1 = chit->
Cell();
526 edepClose1 = rhit.
GeV();
528 else if(cellDist<cellCloseDist2){
529 cellCloseDist2 = cellDist;
530 cellClose2 = chit->
Cell();
531 edepClose2 = rhit.
GeV();
536 for(
unsigned int iHit = 0; iHit < planeHits.size(); ++iHit){
544 if(chit->
Cell()==cellClose1){
545 if(edepClose1>mipPlane){
547 weight = mipPlane/edepClose1;
548 if(weight<0 || weight>1) {
549 mf::LogWarning(
"BremShowerFilter") <<
"weight = "<<weight<<
" "<<mipPlane<<
" "<<edepClose1<<
" "<<edepClose2;
555 else if(chit->
Cell()==cellClose2){
557 if(edepClose1<mipPlane){
558 if(edepClose1+edepClose2>mipPlane){
559 weight = (-edepClose1 + mipPlane)/edepClose2;
560 if(weight<0 || weight>1) {
561 mf::LogWarning(
"BremShowerFilter") <<
"weight = "<<weight<<
" "<<mipPlane<<
" "<<edepClose1<<
" "<<edepClose2;
575 if(weight<0 || weight>1) {
581 trackHits.push_back(newHit);
583 else if((1-weight)>0)
584 shower.
Add(chit, (1-weight));
591 for(
unsigned int iCell=0; iCell<slc->
NCell(); ++iCell){
596 if(plane<minPlane || plane>maxPlane){
598 trackHits.push_back(newHit);
614 for(
unsigned int iCell=0; iCell<slc->
NCell(); ++iCell){
618 trackHits.push_back(newHit);
633 for(
int iHit = 0; iHit<(
int)trackHits.size(); iHit++ ){
638 for(
int iDigit = 0; iDigit<(
int)newDigits.size(); iDigit++ ){
644 auto it = trkMap.find(std::make_tuple(cHit.
Plane(), cHit.
Cell(), cHit.
TDC()));
645 if(
it == trkMap.end()){
646 showerDigits->push_back(newDigits[iDigit]);
650 const float muonWeight =
it->second.weight;
652 if( muonWeight == 1){
659 if( newDigits[iDigit].IsMC() && newDigits[iDigit].Version() == 0 && newDigits[iDigit].NADC() == 3){
660 newDigits[iDigit].SetADC(0, (1-muonWeight)*cHit.
ADC(0) );
661 newDigits[iDigit].SetADC(1, (1-muonWeight)*cHit.
ADC(1));
662 newDigits[iDigit].SetADC(2, (1-muonWeight)*cHit.
ADC(2));
664 else if(newDigits[iDigit].Version() == 0 )
665 newDigits[iDigit].SetADC(0, (1-muonWeight)*cHit.
ADC(0) );
671 int nadc = newDigits[iDigit].NADC();
673 for(
int iadc = 0; iadc < nadc; ++iadc){
674 int16_t newadc = ((newDigits[iDigit].ADC(iadc) -
baseline )*( 1-muonWeight) ) + baseline;
675 newDigits[iDigit].SetADC( iadc, newadc);
679 showerDigits->push_back(newDigits[iDigit]);
691 evt.
put(std::move(showerDigits));
692 evt.
put(std::move(showercol));
703 bool isContained =
false;
705 double xyzMax[3], xyzMin[3];
739 bool isContained =
false;
759 for(
int iTrajPt=0; iTrajPt<nTrajPt; iTrajPt++){
765 isContained =
inFiducial(xTrajpt, yTrajpt, zTrajpt);
792 std::map<unsigned int, double> ePlane;
793 std::map<unsigned int, double> ePlaneAve;
798 for(
unsigned int iCell=0; iCell<trk->
NCell(); ++iCell){
808 ePlane[cHit->
Plane()] += rHit.
GeV();
817 for(
int iPlane=minPlane; iPlane<=
maxPlane; iPlane++){
819 if(iPlane == minPlane) ePlaneAve[iPlane] = 0.5*(ePlane[iPlane] + ePlane[iPlane+1]);
820 else if(iPlane == maxPlane) ePlaneAve[iPlane] = 0.5*(ePlane[iPlane-1] + ePlane[iPlane]);
821 else ePlaneAve[iPlane] = (ePlane[iPlane-1] + ePlane[iPlane] + ePlane[iPlane+1])/3;
824 bool isShower =
false;
826 bool showerEnd =
false;
828 const int nPlaneStart = 5;
829 const int nPlaneEnd = 5;
834 for(
int iPlane=minPlane; iPlane<=
maxPlane; iPlane++){
835 double mipDeDx = 0.00157;
840 if(iPlane<=(maxPlane-nPlaneStart))
841 for(
int k=0; k<nPlaneStart; ++k){
842 if(k==0) showerStart= (ePlane[iPlane+k]>2*mipPlane);
843 else showerStart *= (ePlane[iPlane+k]>2*mipPlane);
844 if(!showerStart)
break;
846 else showerStart =
false;
854 for(
int k=0; k<nPlaneEnd; k++)
857 if(k==0) showerEnd = (ePlaneAve[iPlane+k]<1.5*mipPlane && ePlaneAve[iPlane+k]>0.5*mipPlane);
858 else showerEnd *= (ePlaneAve[iPlane+k]<1.5*mipPlane && ePlaneAve[iPlane+k]>0.5*mipPlane);
859 if(!showerEnd)
break;
872 for(
int iPlane = startPlane; iPlane <=
endPlane; iPlane++) {
873 double mipDeDx = 0.00157;
875 eshower += ePlane[iPlane] - mipPlane;
1024 if ( particle->
Process() !=
"Decay" )
1041 if ( particle->
Momentum().E() < 0.06)
continue;
1068 const std::vector<sim::FLSHit>& flshitsEl
1071 int minPlane = 1000;
1074 for(
unsigned int h = 1;
h < flshitsEl.size(); ++
h){
1075 int plane=flshitsEl[
h].GetPlaneID();
1076 if(plane<minPlane) minPlane =
plane;
1077 if(plane>maxPlane) maxPlane =
plane;
1080 startPlane = minPlane;
TH1F * fHStartContainment
size_t NTrajectoryPoints() const
SubRunNumber_t subRun() const
back track the reconstruction to the simulation
const TLorentzVector & Position(const int i=0) const
unsigned int NCell(geo::View_t view) const
Number of cells in view view.
void GetCenter(double *xyz, double localz=0.0) const
TVector3 TrajectoryPoint(unsigned int i) const
The ith point on the trajectory, a 3-vector in cm.
int32_t TDC() const
The time of the last baseline sample.
fvar< T > fabs(const fvar< T > &x)
const sim::ParticleNavigator & ParticleNavigator() const
Get a reference to the ParticleNavigator.
unsigned short Plane() const
const CellGeo * Cell(int icell) const
std::vector< sim::FLSHit > ParticleToFLSHit(const int &trackID) const
All the FLSHits that were created by the track id trackID, sorted from most to least light...
list_type::const_iterator const_iterator
Vertical planes which measure X.
A collection of associated CellHits.
bool trackEndContained(art::Ptr< rb::Track > &trk)
const PlaneGeo * Plane(unsigned int i) const
DEFINE_ART_MODULE(TestTMapFile)
virtual TVector3 Start() const
std::string Process() const
rb::CellHit MakeCellHit(const rawdata::RawDigit *rawdigit)
Calibrated quantities relying on position in the orthogonal view. To generate a rb::CellHit from a rb...
virtual void Add(const art::Ptr< rb::CellHit > &cell, double weight=1)
ProductID put(std::unique_ptr< PROD > &&product)
unsigned short Cell() const
Track finder for cosmic rays.
bool trackStartContained(art::Ptr< rb::Track > &trk)
virtual ~BremShowerFilter()
T get(std::string const &key) const
virtual TVector3 Dir() const
Unit vector describing prong direction.
rb::RecoHit RecoHit(const art::Ptr< rb::CellHit > &chit) const
Return calibrated hit based on assumed W coordinate.
void findShowerByReco(art::Ptr< rb::Track > &trk, int &startPlane, int &endPlane)
bool IsCalibrated() const
You MUST check here before accessing PECorr, MIP or GeV.
std::string fTrackLabel
label of module making fls hits
double DetHalfHeight() const
Perform a "2 point" Hough transform on a collection of hits.
const art::ProductToken< std::vector< rb::Track > > fTrackToken
void reconfigure(const fhicl::ParameterSet &pset)
unsigned int MinPlane(geo::View_t view=geo::kXorY) const
EventNumber_t event() const
art::Ptr< rb::CellHit > Cell(geo::View_t view, unsigned int viewIdx) const
Get the ith cell from view view.
A rawdata::RawDigit with channel information decoded.
T * make(ARGS...args) const
double DetHalfWidth() const
BremShowerFilter(fhicl::ParameterSet const &pset)
int16_t ADC(uint32_t i) const
art::Ptr< rb::CellHit > hit
const TLorentzVector & Momentum(const int i=0) const
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
double MeanTNS(rb::AveragingScheme scheme=kDefaultScheme) const
bool HaveTruthInfo() const
Is this a file with truth info in? (Is BackTracker going to be any use to you?)
Simple hit+weight pair, returned from rb::Cluster::WeightedHits.
unsigned int MaxPlane(geo::View_t view=geo::kXorY) const
const art::ProductToken< std::vector< rb::Cluster > > fClusterToken
void findShowerByTruth(art::Ptr< rb::Track > &trk, int &startPlane, int &endPlane)
bool IsNoise() const
Is the noise flag set?
bool getByToken(ProductToken< PROD > const &token, Handle< PROD > &result) const
bool fWriteParentSliceMode
virtual void Clear()
Forget about all owned cell hits.
ProductToken< T > consumes(InputTag const &)
Encapsulate the geometry of one entire detector (near, far, ndos)
bool inFiducial(double x, double y, double z)
bool isInsideFiducialVolume(const double x_cm, const double y_cm, const double z_cm) const
Is the particle inside the detector Fiducial Volume?
virtual bool filter(art::Event &evt)
const art::ProductToken< std::vector< rb::CellHit > > fCellHitToken