21 #include "art_root_io/TFileService.h" 22 #include "art_root_io/TFileDirectory.h" 23 #include "canvas/Persistency/Common/FindManyP.h" 63 #include "TDirectory.h" 71 #include "TGraphErrors.h" 74 #include "TTimeStamp.h" 171 float fMaxNoise = 40.;
172 TH1F* fWaveFormHist[10];
192 throw cet::exception(
"AdcThresholdRoiFinder") <<
"Both RawDigitLabel and WireProducerLabel are empty";
196 throw cet::exception(
"AdcThresholdRoiFinder") <<
"Only one of RawDigitLabel and WireProducerLabel should be set";
202 fNticks = detProp.NumberTimeSamples();
205 cout <<
"Numer of clock ticks per event: " <<
fNticks <<
endl;
244 std::vector< art::Ptr<raw::RawDigit> > rawdigitlist;
246 auto rawdigitListHandle = e.
getHandle< std::vector<raw::RawDigit> >(itag1);
247 if (rawdigitListHandle) {
254 std::vector<art::Ptr<recob::Wire> > wirelist;
256 auto wireListHandle = e.
getHandle< std::vector<recob::Wire> >(itag2);
257 if (wireListHandle) {
264 std::vector< art::Ptr<recob::Hit> > hitlist;
271 std::vector< art::Ptr<recob::Track> > tracklist;
273 if (trackListHandle) {
284 art::FindManyP<recob::Hit, recob::TrackHitMeta> fmhittrkmeta(trackListHandle, e,
fTrackModuleLabel);
290 int nwaveform_plane_0 = 0;
291 int nwaveform_plane_1 = 0;
292 int nwaveform_plane_2 = 0;
295 for (
const auto&
trk : tracklist) {
301 auto start =
trk->Vertex();
303 auto start_dir =
trk->VertexDirection();
304 auto end_dir =
trk->EndDirection();
310 trkstart[
ntrks][1] = start.Y();
311 trkstart[
ntrks][2] = start.Z();
326 if (fmtrkcalo.isValid()) {
327 std::vector<art::Ptr<anab::Calorimetry>> calos = fmtrkcalo.at(
ntrks);
328 for (
size_t icalo=0; icalo<calos.size(); icalo++) {
329 if (!calos[icalo])
continue;
330 if (!calos[icalo]->
PlaneID().isValid)
continue;
331 int planenum = calos[icalo]->PlaneID().Plane;
332 if (planenum<0 || planenum>2)
continue;
334 const size_t NHits = calos[icalo] ->
dEdx().size();
338 for (
size_t iHit=0; iHit<NHits; ++iHit) {
339 cout <<
"plane: "<< planenum <<
"; pitch: " << (calos[icalo]->TrkPitchVec())[iHit] <<
endl;
340 if ((calos[icalo]->TrkPitchVec())[iHit]>1)
continue;
341 const auto& TrkPos = (calos[icalo] -> XYZ())[iHit];
346 for(
size_t iHit = 0; iHit < NHits; ++iHit) {
347 if ((calos[icalo]->TrkPitchVec())[iHit]>1)
continue;
348 const auto& TrkPos1 = (calos[icalo] -> XYZ())[iHit];
349 double x = TrkPos1.X()-minx;
350 double XDriftVelocity = detProp.DriftVelocity()*1e-3;
351 double t = x/(XDriftVelocity*1000);
354 trkdqdx[
ntrks][planenum][iHit] = (calos[icalo]->dQdx())[iHit];
360 std::vector<art::Ptr<recob::Hit>> allhits = fmtrkhit.at(
ntrks);
362 for (
size_t ihit=0; ihit<allhits.size(); ihit++) {
364 unsigned int wireplane = allhits[ihit]->WireID().Plane;
365 if (wireplane <0 || wireplane>2)
continue;
366 unsigned int wire = allhits[ihit]->WireID().Wire;
367 unsigned int tpc = allhits[ihit]->WireID().TPC;
368 unsigned int channel = allhits[ihit]->Channel();
370 if (channelStatus.
IsBad(channel))
continue;
373 double xyz[3] = {-9999.0, -9999.0, -9999.0};
374 bool fBadhit =
false;
376 if (fmhittrkmeta.isValid()) {
377 auto vhit = fmhittrkmeta.at(
ntrks);
378 auto vmeta = fmhittrkmeta.data(
ntrks);
380 for (
size_t ii=0; ii<vhit.size(); ii++) {
381 if (vhit[ii].
key() == allhits[ihit].key()) {
391 if (vmeta[ii]->
Index() >=
trk->NumberTrajectoryPoints()) {
392 throw cet::exception(
"Calorimetry_module.cc") <<
"Requested track trajectory index "<<vmeta[ii]->Index()<<
" exceeds the total number of trajectory points "<<
trk->NumberTrajectoryPoints()<<
" for track index "<<
ntrks<<
". Something is wrong with the track reconstruction. Please contact tjyang@fnal.gov!!";
395 if (!
trk->HasValidPoint(vmeta[ii]->Index())) {
400 auto loc =
trk->LocationAtPoint(vmeta[ii]->
Index());
412 if (fBadhit)
continue;
424 double angleToVert = geom->
WireAngleToVertical(geom->
View(allhits[ihit]->WireID()), allhits[ihit]->
WireID().TPC, allhits[ihit]->WireID().Cryostat)-0.5*::util::pi<>();
428 const auto&
dir =
trk->DirectionAtPoint(0);
433 double tmp_cosgamma =
abs(sin(angleToVert)*
dir.Y() + std::cos(angleToVert)*
dir.Z());
453 std::vector<float> adcvec(datasize);
457 if (!rawdigitlist.empty()) {
458 int key_rawdigit = -1;
459 for (
size_t ird=0; ird<rawdigitlist.size(); ++ird) {
460 if (rawdigitlist[ird]->Channel() ==
channel) {
466 if (key_rawdigit == -1)
continue;
467 int datasize_tmp = rawdigitlist[key_rawdigit]->Samples();
468 if (datasize_tmp != datasize)
continue;
471 std::vector<short> rawadc(datasize);
472 raw::Uncompress(rawdigitlist[key_rawdigit]->ADCs(), rawadc, rawdigitlist[key_rawdigit]->Compression());
475 ped[
ntrks][ihit] = rawdigitlist[key_rawdigit]->GetPedestal();
477 for (
size_t jj=0; jj<rawadc.size(); jj++) {
478 adcvec[jj] = rawadc[jj] -
ped[
ntrks][ihit];
481 else if (!wirelist.empty()) {
483 for (
size_t iw=0; iw<wirelist.size(); ++iw) {
484 if (wirelist[iw]->Channel() ==
channel) {
490 if (key_wire == -1)
continue;
491 const auto & signal = wirelist[key_wire]->Signal();
492 if (
int(signal.size()) != datasize)
continue;
494 for (
size_t jj=0; jj<signal.size(); jj++) {
495 adcvec[jj] = signal[jj];
500 int t0 = allhits[ihit]->PeakTime() - 5*(allhits[ihit]->RMS());
502 int t1 = allhits[ihit]->PeakTime() + 5*(allhits[ihit]->RMS());
503 if (t1>= datasize) t1 = datasize - 1;
507 float temp_max_pulseheight = -9999.;
509 int temp_t_max_pulseheight = -1;
510 for (
int itime=t0; itime <=
t1; itime++) {
511 if (adcvec[itime] > temp_max_pulseheight) {
512 temp_max_pulseheight = adcvec[itime];
513 temp_t_max_pulseheight = itime;
526 amp[
ntrks][ihit] = temp_max_pulseheight;
527 tamp[
ntrks][ihit] = temp_t_max_pulseheight;
532 int end_ped = datasize-1;
535 for (
int iped=start_ped; iped<=end_ped; iped++) {
536 if (iped > t0 && iped < t1)
continue;
538 temp_sum += adcvec[iped]*adcvec[iped];
547 for (
int jj=0; jj<datasize; jj++) {
548 if (jj > t0 && jj < t1)
continue;
549 if (
abs(adcvec[jj]) > fMaxNoise)
continue;
550 h1_noise->Fill(adcvec[jj]);
552 TF1 *f1_noise =
new TF1(
"f1_noise",
"gaus" , -fMaxNoise, fMaxNoise);
554 h1_noise->Fit(f1_noise,
"WWQ");
555 f1_noise->GetParameters(&par[0]);
558 if (
fSaveWaveForm && nwaveform<10 && nwaveform_plane_0<4 && nwaveform_plane_1<4 && nwaveform_plane_2<5) {
559 if (wireplane==0) nwaveform_plane_0++;
560 if (wireplane==1) nwaveform_plane_1++;
561 if (wireplane==2) nwaveform_plane_2++;
563 fWaveForm[nwaveform]->SetNameTitle(Form(
"plane_%d_AdcChannel_%d", wireplane, channel), Form(
"AdcChannel%d", channel));
565 for (
int jj=0; jj<datasize; jj++) {
566 fWaveForm[nwaveform]->SetBinContent(jj+1, adcvec[jj]);
569 fWaveFormHist[nwaveform]->SetNameTitle(Form(
"Noise_%d_AdcChannel_%d", wireplane, channel), Form(
"NhistChannel%d", channel));
570 for (
int tt=1;
tt<=h1_noise->GetNbinsX();
tt++){
589 fEventTree = tfs->make<TTree>(
"Event",
"Event");
637 for (
int i=0; i<10; i++) {
640 fWaveForm[i]->GetXaxis()->SetTitle(
"Time [ticks]");
641 fWaveForm[i]->GetYaxis()->SetTitle(
"ADC");
662 for (
int j=0; j<3; j++) {
677 trkx[i][j][
k] = -9999.0;
678 trkt[i][j][
k] = -9999.0;
def analyze(root, level, gtrees, gbranches, doprint)
virtual bool IsBad(raw::ChannelID_t channel) const =0
Returns whether the specified channel is bad in the current run.
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
code to link reconstructed objects back to the MC truth information
float noisermsfit[kMaxTracks][kMaxHits]
int wireid[kMaxTracks][kMaxHits]
constexpr std::uint32_t timeLow() const
std::string fCalorimetryModuleLabel
int chid[kMaxTracks][kMaxHits]
int tamp[kMaxTracks][kMaxHits]
Handle< PROD > getHandle(SelectorBase const &) const
constexpr std::uint32_t timeHigh() const
float trkdqdx[kMaxTracks][3][kMaxHits]
float trkthetaxz[kMaxTracks]
float ped[kMaxTracks][kMaxHits]
float hit_plane[kMaxTracks][kMaxHits]
std::vector< int > fSelectedWires
int tpcid[kMaxTracks][kMaxHits]
void analyze(art::Event const &e) override
float noiserms[kMaxTracks][kMaxHits]
float trkend[kMaxTracks][3]
float trkx[kMaxTracks][3][kMaxHits]
object containing MC flux information
art framework interface to geometry description
float trkthetayz[kMaxTracks]
double trkhitx[kMaxHits][3][kMaxHits]
std::string fTrackModuleLabel
float amp[kMaxTracks][kMaxHits]
QTextStream & reset(QTextStream &s)
double dEdx(float dqdx, float Efield)
#define DEFINE_ART_MODULE(klass)
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
double trkhity[kMaxHits][3][kMaxHits]
std::string fWireInstanceLabel
SubRunNumber_t subRun() const
float trkstart[kMaxTracks][3]
Class providing information about the quality of channels.
static int max(int a, int b)
Signal2Noise(fhicl::ParameterSet const &p)
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
Definition of data types for geometry description.
std::string fRawInstanceLabel
float trkendcosxyz[kMaxTracks][3]
Declaration of signal hit object.
std::string fHitModuleLabel
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
int ntrkhits[kMaxTracks][3]
std::string fRawDigitLabel
Provides recob::Track data product.
std::string fWireProducerLabel
Interface for experiment-specific channel quality info provider.
EventNumber_t event() const
Declaration of basic channel signal object.
detail::Node< FrameID, bool > PlaneID
double trkhitz[kMaxHits][3][kMaxHits]
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Interface for experiment-specific service for channel quality info.
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
float trkstartcosxyz[kMaxTracks][3]
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
float trkt[kMaxTracks][3][kMaxHits]
double WireAngleToVertical(geo::View_t view, geo::TPCID const &tpcid) const
Returns the angle of the wires in the specified view from vertical.
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)
Event finding and building.
double cosgma[kMaxTracks][kMaxHits]