cf252.driftVel4.42_noMask2.nEv2k.trees.root (1.29 MB)I’m wanting to plot TPolyLine3D on the same canvas as a set of charge voxels, however when I uncomment the trk_n loop I get a segfault after the first trk_n loop iteration; why is this happening? I’ve attached cf252.driftVel4.42_noMask2.nEv2k.trees.root and digTrk200.root (in the original post).
// for (int trk_n = 1; trk_n < trackCount_hist->FindFirstBinAbove(0); ++trk_n)
// {
// pl_track->SetPoint(0,start_x[trk_n],start_y[trk_n],start_z[trk_n]);
// pl_track->SetPoint(1,end_x[trk_n],end_y[trk_n],end_z[trk_n]);
// pl_track->Draw("same");
// }
///////// digits plus track /////////
printf("///////// digits plus track /////////\n");
///////// initialize track tree /////////
printf("///////// initialize track tree /////////\n\n");
sprintf(noMaskTrackFileName,"/p/lscratche/jerbundg/data/thesisData/trees/%s.driftVel%s_noMask%d.nEv10k.trees.root",actinide,driftVel,preamp);
printf("noMaskTrackFileName: %s\n", noMaskTrackFileName);
TFile* noMaskTrackFile = new TFile(noMaskTrackFileName);
TTree *noMaskTracks; noMaskTrackFile->GetObject("tracks", noMaskTracks);
///////// initialize digit tree /////////
printf("///////// initialize digit tree /////////\n\n");
sprintf(noMaskDigitFileName,"/p/lscratche/jerbundg/data/thesisData/trees/digTrkTreeDir/noMask%d.driftVel%s_trk_dig.2k.trees.root",preamp,driftVel);
TFile* noMaskDigitFile = new TFile(noMaskDigitFileName);
TDirectory *cwd = gDirectory; // we create histograms "here"
TH3F *track3d = new TH3F("track3d", "track3d", 12, -5, 5, 12, -5, 5, 12, -1, 5);
track3d->SetStats(kTRUE);
TTree *noMaskDigits; noMaskDigitFile->GetObject("tracks", noMaskDigits);
noMaskDigits->SetMarkerStyle(20);
cwd->cd(); // go to the directory where histograms are
const int first_run = 100002055;
const int last_run = 100002061;
const int first_event = 0;
const int last_event = 2000;
TH1F* trackCount_hist = new TH1F("trackCount_hist","trackCount_hist",10,0,10);
TH1F* start_hist = new TH1F("start_hist","start_hist",1000,-20,20);
double start_x[10];
double start_y[10];
double start_z[10];
TH1F* end_hist = new TH1F("end_hist","end_hist",1000,-20,20);
double end_x[10];
double end_y[10];
double end_z[10];
TPolyLine3D *pl_track = new TPolyLine3D(2);
pl_track->SetLineColor(kYellow);
pl_track->SetLineWidth(2);
for (int run = first_run; run <= last_run; run++)
{
std::cout << "////// event tracks for run: " << run << " ////////" << std::endl;
for (int event_id = first_event; event_id <= last_event; event_id++)
{
char individ_eventCut[234];
sprintf(individ_eventCut,"fitType==5&&run==%d&&eventID==%d&&trackCount==2", run, event_id);
noMaskTracks->Draw("trackCount>>trackCount_hist",individ_eventCut);
if (trackCount_hist->GetEntries()==0) continue;
for (int trk_n = 1; trk_n < trackCount_hist->FindFirstBinAbove(0); ++trk_n)
{
sprintf(buffChar,"%s&&%d",individ_eventCut,trk_n);
noMaskTracks->Draw("start.x()>>start_hist",buffChar);
start_x[trk_n] = start_hist->GetMean();
noMaskTracks->Draw("start.y()>>start_hist",buffChar);
start_y[trk_n] = start_hist->GetMean();
noMaskTracks->Draw("start.z()>>start_hist",buffChar);
start_z[trk_n] = start_hist->GetMean();
noMaskTracks->Draw("end.x()>>end_hist",buffChar);
end_x[trk_n] = end_hist->GetMean();
noMaskTracks->Draw("end.y()>>end_hist",buffChar);
end_y[trk_n] = end_hist->GetMean();
noMaskTracks->Draw("end.z()>>end_hist",buffChar);
end_z[trk_n] = end_hist->GetMean();
}
track3d->SetTitle(individ_eventCut);
// https://root-forum.cern.ch/t/problem-with-tree-and-histogram/21240/12
track3d->Reset("M"); // make sure it's "clean"
if (!(track3d->TestBit(TH1::kNoStats)))
{
noMaskDigits->Project("track3d", "dig_x:dig_y:dig_z", individ_eventCut, "");
((TArrayF *)track3d)->Reset(); // "reset" histogram's bins' contents
}
noMaskDigits->Draw("dig_x:dig_y:dig_z:dig_adc>>track3d", individ_eventCut, "col");
TPolyLine3D *pl_hex = new TPolyLine3D(5);
pl_hex->SetLineColor(kSpring);
pl_hex->SetLineWidth(2);
for (int n = 0; n <= 6; ++n)
pl_hex->SetPoint(n,
5*TMath::Cos(n*60*TMath::Pi()/180),
5*TMath::Sin(n*60*TMath::Pi()/180),
5);
pl_hex->Draw("same");
TPolyLine3D *pl_circle = new TPolyLine3D(5);
pl_circle->SetLineColor(kRed);
pl_circle->SetLineWidth(2);
for (int n = 0; n <= 60; ++n)
pl_circle->SetPoint(n,
5*TMath::Cos(n*6*TMath::Pi()/180),
5*TMath::Sin(n*6*TMath::Pi()/180),
0);
pl_circle->Draw("same");
// for (int trk_n = 1; trk_n < trackCount_hist->FindFirstBinAbove(0); ++trk_n)
// {
// pl_track->SetPoint(0,start_x[trk_n],start_y[trk_n],start_z[trk_n]);
// pl_track->SetPoint(1,end_x[trk_n],end_y[trk_n],end_z[trk_n]);
// pl_track->Draw("same");
// }
sprintf(buffChar,"run%d_eventID%d.png", run, event_id);
c1->SaveAs(buffChar);
}
}