16 #include "art_root_io/TFileService.h" 115 std::vector<art::Ptr<recob::Track> > tracklist;
121 std::vector<art::Ptr<raw::ExternalTrigger> > countlist;
127 std::vector<art::Ptr<raw::RawDigit> > rawlist;
133 std::vector<art::Ptr<recob::Wire> > wirelist;
139 art::FindManyP<recob::Hit, recob::TrackHitMeta> fmthm(trackListHandle, e,
fTrackModuleLabel);
146 std::vector<int> ci1;
147 std::vector<int> ci2;
149 for (
size_t i = 0; i<countlist.size(); ++i){
150 for (
size_t j = 0; j<countlist.size(); ++j){
152 if (
std::abs(countlist[i]->GetTrigTime()-countlist[j]->GetTrigTime()) < 2){
157 if ( ( countlist[i]->GetTrigID() >= 6 && countlist[i]->GetTrigID() <= 15 && countlist[j]->GetTrigID() >= 28 && countlist[j]->GetTrigID() <= 37 )
158 || ( countlist[i]->GetTrigID() <= 5 && countlist[j]->GetTrigID() >= 22 && countlist[j]->GetTrigID() <= 27 )
159 || ( countlist[i]->GetTrigID() >= 16 && countlist[i]->GetTrigID() <= 21 && countlist[j]->GetTrigID() >= 38 && countlist[j]->GetTrigID() <= 43 )
165 c1.push_back(countlist[i]->GetTrigID());
166 c2.push_back(countlist[j]->GetTrigID());
173 std::cout<<
"counter array size = "<<c1.size()<<
" tracklist size = "<<tracklist.size()<<
std::endl;
174 if (c1.size()&&tracklist.size()){
175 double ccosx = (
cx[c1[0]]-
cx[c2[0]])/sqrt(
pow(
cx[c1[0]]-
cx[c2[0]],2)+
pow(
cy[c1[0]]-
cy[c2[0]],2)+
pow(
cz[c1[0]]-
cz[c2[0]],2));
176 double ccosy = (
cy[c1[0]]-
cy[c2[0]])/sqrt(
pow(
cx[c1[0]]-
cx[c2[0]],2)+
pow(
cy[c1[0]]-
cy[c2[0]],2)+
pow(
cz[c1[0]]-
cz[c2[0]],2));
177 double ccosz = (
cz[c1[0]]-
cz[c2[0]])/sqrt(
pow(
cx[c1[0]]-
cx[c2[0]],2)+
pow(
cy[c1[0]]-
cy[c2[0]],2)+
pow(
cz[c1[0]]-
cz[c2[0]],2));
183 for (
size_t i = 0; i<tracklist.size(); ++i){
185 std::tie(trackStart, trackEnd) = tracklist[i]->Extent();
186 larStart = tracklist[i]->VertexDirection();
187 larEnd = tracklist[i]->EndDirection();
189 double dc =
std::abs(ccosx*larStart.X()+ccosy*larStart.Y()+ccosz*larStart.Z());
207 double ctime = (countlist[ci1[0]]->GetTrigTime() + countlist[ci2[0]]->GetTrigTime())/(2*32.);
208 double x0 = trackStart.X() + (trackStart.X()>0?-1:1)*ctime*0.5*0.1085;
210 double z0 = trackStart.Z();
211 double x1 = trackEnd.X() + (trackStart.X()>0?-1:1)*ctime*0.5*0.1085;
213 double z1 = trackEnd.Z();
217 if (c1[0]>=6&&c1[0]<=15){
218 dx1 =
std::abs(x0+(
cz[c1[0]]-z0)*(x0-x1)/(z0-z1)-
cx[c1[0]]);
220 if (c2[0]>=28&&c2[0]<=37){
221 dx2 =
std::abs(x0+(
cz[c2[0]]-z0)*(x0-x1)/(z0-z1)-
cx[c2[0]]);
224 hdx->Fill(x0+(
cz[c1[0]]-z0)*(x0-x1)/(z0-z1)-
cx[c1[0]]);
225 hdx->Fill(x0+(
cz[c2[0]]-z0)*(x0-x1)/(z0-z1)-
cx[c2[0]]);
226 if (dx1>40||dx2>40)
continue;
227 for (
size_t j = 0; j<tracklist[i]->NumberTrajectoryPoints(); ++j){
228 auto loc = tracklist[i]->LocationAtPoint(j);
231 hxz->Fill(
loc.Z(),
loc.X()-ctime*0.5*0.1085);
234 hxz->Fill(
loc.Z(),
loc.X()+ctime*0.5*0.1085);
238 std::map<size_t,art::Ptr<recob::Hit> > hitmap;
239 std::map<size_t,int> indexmap;
240 std::map<size_t,double> xposmap;
241 if (fmthm.isValid()){
242 auto vhit = fmthm.at(i);
243 auto vmeta = fmthm.data(i);
245 std::map<geo::PlaneID, std::vector<std::pair<int, double>>> planehits;
247 for (
size_t h = 0;
h < vhit.size(); ++
h){
248 auto loc = tracklist[i]->LocationAtPoint(vmeta[
h]->
Index());
250 hitmap[vhit[
h]->WireID().Wire] = vhit[
h];
251 indexmap[vhit[
h]->WireID().Wire] = vmeta[
h]->Index();
252 xposmap[vhit[
h]->WireID().Wire] =
loc.X()-ctime*0.5*0.1085;
254 planehits[vhit[
h]->WireID().planeID()].push_back(std::make_pair(vhit[
h]->
WireID().
Wire, vhit[
h]->PeakTime()));
256 double xyzStart[3], xyzEnd[3];
258 double xhit, yhit, zhit;
262 xyzEnd[1], xyzEnd[2],
263 cy[c1[0]],
cz[c1[0]],
264 cy[c2[0]],
cz[c2[0]],
266 xhit =
cx[c1[0]] + (
cx[c2[0]]-
cx[c1[0]])/(
cy[c2[0]]-
cy[c1[0]])*(yhit-
cy[c1[0]]);
267 hdt->Fill(vhit[
h]->PeakTime() - detProp.ConvertXToTicks(xhit+(vhit[
h]->WireID().TPC%2==1?1:-1)*ctime*0.5*0.1085, vhit[
h]->
WireID()));
272 for (
auto &plhits : planehits){
275 std::vector<float>
x,
y, ey;
276 for (
auto &
hit : plhits.second){
277 if (
hit.first < w0) w0 =
hit.first;
278 if (
hit.first > w1) w1 =
hit.first;
279 x.push_back(
hit.first);
280 y.push_back(
hit.second);
283 if (w0!=INT_MAX&&w1!=INT_MIN&&(w1-w0>5)&&plhits.second.size()>2){
284 float intcpt, slope, intcpterr, slopeerr, chidof;
287 std::map<raw::ChannelID_t, int> chused;
288 for (
int w = w0;
w<=w1; ++
w){
292 if (chused.find(
channel)==chused.end()){
293 double tick = intcpt + slope*
w;
294 double x = detProp.ConvertTicksToX(tick, wid);
295 x += (wid.
TPC%2==1?-1:1)*ctime*0.5*0.1085;
296 double xyzStart[3], xyzEnd[3];
301 for (
size_t j = 0; j<rawlist.size(); ++j){
302 if (rawlist[j]->Channel() ==
channel){
303 double pedestal = rawlist[j]->GetPedestal();
305 for (
size_t k = 0;
k<rawlist[j]->NADC(); ++
k){
306 if (
float(
k)>=tick&&
float(
k)<=tick+20){
307 if (
int(rawlist[j]->ADC(
k)-pedestal)>maxph){
308 maxph =
int(rawlist[j]->ADC(
k)-pedestal);
316 for (
size_t k = 0;
k<rawlist[j]->NADC(); ++
k){
317 if ((
int(
k)>besttime-200&&
int(
k)<besttime-100)||
318 (
int(
k)>besttime+100&&
int(
k)<besttime+200)){
319 mean += rawlist[j]->ADC(
k)-pedestal;
320 mean2 +=
pow(rawlist[j]->ADC(
k)-pedestal,2);
328 const auto&
dir = tracklist[i]->DirectionAtPoint(0);
329 double cosgamma =
std::abs(std::sin(angleToVert)*
dir.Y() + std::cos(angleToVert)*
dir.Z());
333 hbkg[wid.
TPC][wid.
Plane][0]->Fill(sqrt(mean2-mean*mean));
336 if (besttime<0||besttime>=15000)
continue;
337 for (
size_t j = 0; j<wirelist.size(); ++j){
338 if (wirelist[j]->Channel() ==
channel){
339 double maxph1 = wirelist[j]->Signal()[besttime];
343 for (
size_t k = 0;
k<wirelist[j]->NSignal(); ++
k){
344 if ((
int(
k)>besttime-200&&
int(
k)<besttime-100)||
345 (
int(
k)>besttime+100&&
int(
k)<besttime+200)){
346 mean += wirelist[j]->Signal()[
k];
355 const auto&
dir = tracklist[i]->DirectionAtPoint(0);
356 double cosgamma =
std::abs(std::sin(angleToVert)*
dir.Y() + std::cos(angleToVert)*
dir.Z());
360 hbkg[wid.
TPC][wid.
Plane][1]->Fill(sqrt(mean2-mean*mean));
370 if (hitmap.size()>=10){
371 for (
size_t h = 0;
h<geom->
Nwires(2,5,0); ++
h){
375 if (hitmap.find(
h)!=hitmap.end()){
376 pt = hitmap[
h]->PeakTime();
380 std::vector<double> vw;
381 std::vector<double> vt;
382 std::vector<double> vx;
383 for (
auto& hv : hitmap){
387 vw.push_back((hv.second)->WireID().Wire);
388 vt.push_back((hv.second)->PeakTime());
389 vx.push_back(xposmap[hv.first]);
393 TGraph *gr =
new TGraph(vw.size(), &vw[0], &vt[0]);
396 gr =
new TGraph(vw.size(), &vw[0], &vx[0]);
402 double maxph = -1e10;
403 for (
size_t j = 0; j<rawlist.size(); ++j){
405 double pedestal = rawlist[j]->GetPedestal();
406 for (
size_t k = 0;
k<rawlist[j]->NADC(); ++
k){
407 if (
float(
k)>=pt&&
float(
k)<=pt+20){
408 if (rawlist[j]->ADC(
k)-pedestal>maxph){
409 maxph = rawlist[j]->ADC(
k)-pedestal;
415 double angleToVert = geom->
WireAngleToVertical(hitmap.begin()->second->View(), hitmap.begin()->second->WireID().TPC, hitmap.begin()->second->WireID().Cryostat) - 0.5*::util::pi<>();
418 const auto&
dir = tracklist[i]->VertexDirection();
419 double cosgamma =
std::abs(std::sin(angleToVert)*
dir.Y() + std::cos(angleToVert)*
dir.Z());
420 hphx->Fill(xpos,maxph*cosgamma/geom->
WirePitch(hitmap.begin()->second->View()));
425 dqdx = maxph*cosgamma/geom->
WirePitch(hitmap.begin()->second->View());
440 dcos = tfs->make<TH1D>(
"dcos",
";cos#theta;",100,0,1.1);
443 hxz = tfs->make<TH2D>(
"hxz",
";z (cm);x (cm)",1000,0,160,1000,-50,250);
444 hyz = tfs->make<TH2D>(
"hyz",
";z (cm);y (cm)",1000,0,160,1000,-90,120);
446 for (
int i = 0; i<8; ++i){
447 for (
int j = 0; j<3; ++j){
448 for (
int k = 0;
k<4; ++
k){
449 hsig[i][j][
k]= tfs->make<TH1D>(Form(
"hsig_%d_%d_%d",i,j,
k),Form(
"TPC=%d, Plane=%d, %d",i,j,
k), 200,0,200);
450 hbkg[i][j][
k]= tfs->make<TH1D>(Form(
"hbkg_%d_%d_%d",i,j,
k),Form(
"TPC=%d, Plane=%d, %d",i,j,
k), 100,0,100);
451 hstb[i][j][
k]= tfs->make<TH1D>(Form(
"hstb_%d_%d_%d",i,j,
k),Form(
"TPC=%d, Plane=%d, %d",i,j,
k), 100,0,100);
456 hdx = tfs->make<TH1D>(
"hdx",
";#Delta x (cm)",100,-100,100);
458 hphx = tfs->make<TH2D>(
"hphx",
";x (cm); dQ/dx (ADC/cm)",50,0,250,100,0,600);
460 hdt = tfs->make<TH1D>(
"hdt",
";#Delta t (ticks);",1000,-1000,1000);
462 ftree = tfs->make<TTree>(
"tree",
"a tree for sn analysis");
463 ftree->Branch(
"run", &
run,
"run/I");
464 ftree->Branch(
"event", &
event,
"event/I");
465 ftree->Branch(
"tpc", &
tpc,
"tpc/I");
466 ftree->Branch(
"wire", &
wire,
"wire/I");
467 ftree->Branch(
"trackid", &
trackid,
"trackid/I");
468 ftree->Branch(
"dqdx", &
dqdx,
"dqdx/D");
469 ftree->Branch(
"x", &
x,
"x/D");
474 in.open(
"counterInformation.txt");
477 in.getline(line,1024);
478 if (!in.good())
break;
481 sscanf(line,
"%d %f %f %f",&i,&x,&y,&z);
491 for (
size_t i = 0; i<geom->
NAuxDets(); ++i){
492 auto& auxdet = geom->
AuxDet(i);
494 cx[i] = auxdet.GetCenter().X();
495 cy[i] = auxdet.GetCenter().Y();
496 cz[i] = auxdet.GetCenter().Z();
virtual bool IsBad(raw::ChannelID_t channel) const =0
Returns whether the specified channel is bad in the current run.
Functions to help with numbers.
art::InputTag fTrackModuleLabel
Handle< PROD > getHandle(SelectorBase const &) const
art::InputTag fExternalCounterModuleLabel
CryostatID_t Cryostat
Index of cryostat.
EDAnalyzer(fhicl::ParameterSet const &pset)
geo::Length_t WirePitch(geo::PlaneID const &planeid) const
Returns the distance between two consecutive wires.
void analyze(art::Event const &e) override
trkf::LinFitAlg fLinFitAlg
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.
art framework interface to geometry description
tracking::Vector_t Vector_t
void LinFit(std::vector< float > &x, std::vector< float > &y, std::vector< float > &ey2, float &Intercept, float &Slope, float &InterceptError, float &SlopeError, float &ChiDOF) const
#define DEFINE_ART_MODULE(klass)
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
art::InputTag fCalDataModuleLabel
Class providing information about the quality of channels.
PlaneID_t Plane
Index of the plane within its TPC.
SignalToNoise(fhicl::ParameterSet const &p)
bool IntersectLines(double A_start_x, double A_start_y, double A_end_x, double A_end_y, double B_start_x, double B_start_y, double B_end_x, double B_end_y, double &x, double &y) const
Computes the intersection between two lines on a plane.
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
AuxDetGeo const & AuxDet(unsigned int const ad=0) const
Returns the specified auxiliary detector.
Detector simulation of raw signals on wires.
constexpr auto absDiff(A const &a, B const &b)
Returns the absolute value of the difference between two values.
raw::ChannelID_t PlaneWireToChannel(WireID const &wireid) const
Returns the ID of the TPC channel connected to the specified wire.
Declaration of signal hit object.
void line(double t, double *p, double &x, double &y, double &z)
SignalToNoise & operator=(SignalToNoise const &)=delete
tracking::Point_t Point_t
Provides recob::Track data product.
Interface for experiment-specific channel quality info provider.
void WireEndPoints(geo::WireID const &wireid, double *xyzStart, double *xyzEnd) const
Fills two arrays with the coordinates of the wire end points.
art::InputTag fRawDigitModuleLabel
EventNumber_t event() const
Declaration of basic channel signal object.
auto const & get(AssnsNode< L, R, D > const &r)
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
TPCID_t TPC
Index of the TPC within its cryostat.
Interface for experiment-specific service for channel quality info.
recob::tracking::Plane Plane
Utility functions to extract information from recob::Track
double mean(sqlite3 *db, std::string const &table_name, std::string const &column_name)
double WireAngleToVertical(geo::View_t view, geo::TPCID const &tpcid) const
Returns the angle of the wires in the specified view from vertical.
QTextStream & endl(QTextStream &s)
unsigned int NAuxDets() const
Returns the number of auxiliary detectors.
Event finding and building.