4 #ifndef CTree35t_Module 5 #define CTree35t_Module 42 #include "art_root_io/TFileService.h" 45 #include "canvas/Persistency/Common/FindManyP.h" 50 #include "lbne-raw-data/Overlays/TpcMilliSliceFragment.hh" 51 #include "lbne-raw-data/Overlays/SSPFragment.hh" 52 #include "lbne-raw-data/Overlays/anlTypes.hh" 53 #include "artdaq-core/Data/Fragment.hh" 54 #include "../daqinput35t/tpcFragmentToRawDigits.h" 55 #include "../daqinput35t/PennToOffline.h" 56 #include "../daqinput35t/SSPReformatterAlgs.h" 57 #include "../daqinput35t/utilities/UnpackFragment.h" 61 #include "TDirectory.h" 62 #include "TObjArray.h" 64 #include "TClonesArray.h" 65 #include "TLorentzVector.h" 88 #define MAX_CHANNEL 2048 89 #define MAX_TRACKS 2000 90 #define MAX_HITS 20000 92 #define MAX_CLUSTER 10 93 #define MAX_OPWAVEFORMS 1000 112 void saveChannelWireMap();
113 void saveWireGeometry(
int plane,
int tpc);
114 void printGeometry();
292 : EDAnalyzer(parameterSet)
339 TDirectory* tmpDir = gDirectory;
344 TDirectory* subDir =
fOutFile->mkdir(
"Detector");
346 fGeoTree =
new TTree(
"Geometry",
"Detector Geometry");
370 TDirectory* subDir2 =
fOutFile->mkdir(
"Event");
372 fEventTree =
new TTree(
"Sim",
"Event Tree from Simulation");
454 TDirectory *subDir3 =
fOutFile->mkdir(
"OpDet");
500 auto const* timeService = lar::providerFrom<detinfo::DetectorClocksService>();
501 fSampleFreq = timeService->OpticalClock().Frequency();
509 for (
int i=0; i<
fNTPC; i++) {
542 TGeoNode *fOpNode = (TGeoNode*)fOpDetNode.
Node();
543 TGeoTube *fOpTube = (TGeoTube*)fOpNode->GetVolume()->GetShape();
544 tmp = fOpTube->GetDZ();
546 tmp = fOpTube->GetDY();
554 TDirectory* tmpDir = gDirectory;
601 std::ofstream mapfile;
602 mapfile.open(
"ChannelWireMap.txt");
603 mapfile <<
"# total channels: " <<
fNchannels <<
"\n\n";
606 mapfile <<
"Channel " << i <<
"\n";
607 mapfile <<
"Nwires " << wireids.size() <<
"\n";
610 for (
auto const& wid : wireids) {
611 mapfile << wid.TPC <<
" ";
616 for (
auto const& wid : wireids) {
617 mapfile << wid.Plane <<
" ";
629 for (
auto const& wid : wireids) {
630 mapfile << wid.Wire <<
" ";
632 mapfile <<
"\n" <<
endl;
646 for (
int wire=0; wire<Nwires; wire++) {
648 cout << plane <<
"\t" << wire <<
"\t";
649 for (
int i=0; i<3; i++) {
650 cout << xyzStart[i] <<
"\t";
652 for (
int i=0; i<3; i++) {
653 cout << xyzEnd[i] <<
"\t";
668 TDirectory* tmpDir = gDirectory;
687 for (
int i=0; i<
fNTPC; i++) {
720 fEvent =
event.id().event();
755 for (
int j=0; j<4; j++) {
807 std::vector< art::Ptr<raw::RawDigit> > rawhits;
811 cout <<
"\n Raw Hits size: " << rawhits.size() <<
endl;
815 for (
auto const&
hit : rawhits) {
816 int chanId =
hit->Channel();
817 int nSamples =
hit->Samples();
818 std::vector<short> uncompressed(nSamples);
819 int pedestal = (
int)
hit->GetPedestal();
832 for (
auto const& adc : uncompressed) {
833 short ladc = adc-pedestal;
839 if (!isHit)
continue;
846 int nSavedSamples = 0;
848 bool hasTime =
false;
849 for (
int i=0; i<nSamples; i++) {
850 short adc = uncompressed[i]-pedestal;
853 wfADC.push_back(
int(adc));
887 std::vector< art::Ptr<recob::Wire> > wires;
894 for (
auto const& wire : wires) {
895 std::vector<float> calibwf = wire->Signal();
896 int chanId = wire->Channel();
897 int nSamples = calibwf.size();
900 short thresh = pedstal + 1;
902 for (
auto const& adc : calibwf) {
908 if (!isHit)
continue;
915 int nSavedSamples = 0;
916 for (
int i=0; i<nSamples; i++) {
917 int adc =
int(calibwf[i]);
918 if (adc != pedstal) {
921 wfADC.push_back(adc);
937 event.getByLabel(
"largeant", particleHandle);
940 std::vector< art::Ptr<simb::MCParticle> > particles;
944 event.getByLabel(
"largeant", simChannelHandle);
949 for (
auto const& particle: particles ) {
950 fMC_id[i] = particle->TrackId();
951 fMC_pdg[i] = particle->PdgCode();
954 <<
"\nfMC_id[i] = "<<
fMC_id[i]
955 <<
"\nfMC_pdg[i] = "<<
fMC_pdg[i]
957 int Ndaughters = particle->NumberDaughters();
958 vector<int> daughters;
959 for (
int i=0; i<Ndaughters; i++) {
960 daughters.push_back(particle->Daughter(i));
963 size_t numberTrajectoryPoints = particle->NumberTrajectoryPoints();
964 int last = numberTrajectoryPoints - 1;
965 const TLorentzVector& positionStart = particle->Position(0);
966 const TLorentzVector& positionEnd = particle->Position(last);
967 const TLorentzVector& momentumStart = particle->Momentum(0);
968 const TLorentzVector& momentumEnd = particle->Momentum(last);
974 TClonesArray *Lposition =
new TClonesArray(
"TLorentzVector", numberTrajectoryPoints);
975 TClonesArray *Lmomentum =
new TClonesArray(
"TLorentzVector", numberTrajectoryPoints);
977 for(
unsigned int j=0; j<numberTrajectoryPoints; j++) {
978 new ((*Lposition)[j]) TLorentzVector(particle->Position(j));
979 new ((*Lmomentum)[j]) TLorentzVector(particle->Momentum(j));
1000 std::vector<art::Ptr<recob::Hit> > hitlist;
1006 <<
" hits, MAX ALLOWED: " <<
MAX_HITS;
1008 for (
int i=0; i<
no_hits; i++) {
1019 if(! event.
getByLabel(
"dcheat", tHitListHandle))
return;
1020 std::vector< art::Ptr<recob::Hit> > tHitlist;
1022 nthits = tHitlist.size();
1025 <<
" hits, MAX ALLOWED: " <<
MAX_HITS;
1027 for (
int i=0; i<
nthits; i++) {
1040 std::vector<art::Ptr<recob::Cluster> > clusterlist;
1044 int nclusters = clusterlist.size();
1045 cout<<
"# of clusters is "<<nclusters<<
endl;
1047 for(
size_t i=0; i<clusterlist.size(); ++i){
1049 std::vector< art::Ptr<recob::Hit> > hitslist = fm.at(i);
1050 size_t n_hits = hitslist.size();
1052 for(
size_t j=0; j<n_hits; j++) {
1072 std::vector<art::Ptr<recob::Track> > tracklist;
1084 TClonesArray *Lposition =
new TClonesArray(
"TLorentzVector", numberTrajectoryPoints);
1086 for(
unsigned int j=0; j<numberTrajectoryPoints; j++) {
1087 new ((*Lposition)[j]) TLorentzVector(track->
LocationAtPoint<TVector3>(j), 0);
1099 std::cout <<
"OpHitHandle->size() = " << OpHitHandle->size() <<
std::endl;
1100 std::cout<<
"waveformHandle->size() = "<<waveformHandle->size()<<
std::endl;
1101 for (
size_t i = 0; i < waveformHandle->size(); ++i) {
1104 double extractedTimestamp = pulse.
TimeStamp();
1106 int OpDetNumber =
fGeom->GeometryCore::OpDetFromOpChannel(channel);
1107 std::cout<<i<<
": channel = "<<channel<<
", timestamp = "<<
std::setprecision(15)<<extractedTimestamp<<
", OpDetNumber = "<<OpDetNumber<<
", #Ticks = "<<pulse.size()<<
", fSampleFreq = "<<
fSampleFreq<<
std::endl;
1111 timestamp.at(OpDetNumber).push_back((
int)extractedTimestamp);
1113 TH1D *hwaveform =
new TH1D(Form(
"avgwaveform_channel_%i_%i", channel,
waveformCount[channel]), Form(
"average waveform channel %i %i-waveform", channel,
waveformCount[channel]), pulse.size(), extractedTimestamp, double(pulse.size())/
fSampleFreq+extractedTimestamp);
1201 bool RCEPresent =
true;
1202 try { RCErawFragments->size(); }
1204 std::cout <<
"WARNING: Raw RCE data not found in event " <<
event.event() <<
std::endl;
1209 if(!RCErawFragments.
isValid()){
1210 std::cerr <<
"Run: " <<
event.run() <<
", SubRun: " <<
event.subRun() <<
", Event: " <<
event.event() <<
" is NOT VALID" <<
std::endl;
1215 artdaq::Fragments
const& rawFragmentsRCE = *RCErawFragments;
1216 std::cout<<
"rawFragmentsRCE.size() = "<<rawFragmentsRCE.size()<<
std::endl;
1217 for (
size_t fragIndex=0; fragIndex < rawFragmentsRCE.size(); ++fragIndex ) {
1218 int ThisADCcount = 0;
1219 const artdaq::Fragment &singleFragment = rawFragmentsRCE[fragIndex];
1220 lbne::TpcMilliSliceFragment millisliceFragment(singleFragment);
1221 auto numMicroSlices = millisliceFragment.microSliceCount();
1222 for (
unsigned int i_micro=0;i_micro<numMicroSlices;i_micro++) {
1223 std::unique_ptr <const lbne::TpcMicroSlice> microSlice = millisliceFragment.microSlice(i_micro);
1224 auto numNanoSlices = microSlice->nanoSliceCount();
1225 if (numNanoSlices) {
1227 ThisADCcount += numNanoSlices;
1228 std::cout<<fragIndex<<
": "<<numNanoSlices<<
", "<<ThisADCcount<<
std::endl;
1230 if ( fragIndex==0 && i_micro==0 ) {
1231 std::cout <<
"Getting RCE time for event " <<
event.event();
1232 if ( microSlice->nanoSliceCount() ) {
1233 RCETimeBegin = microSlice->nanoSlice(0)->nova_timestamp();
1241 if ( fragIndex==rawFragmentsRCE.size()-1 && i_micro==numMicroSlices-1) {
1242 RCETimeEnd = microSlice->nanoSlice(numNanoSlices-1)->nova_timestamp();
1244 std::unique_ptr <const lbne::TpcMicroSlice> prevMicroSlice = millisliceFragment.microSlice(i_micro-1);
1245 RCETimeEnd = 2.*microSlice->software_message() - prevMicroSlice->software_message();
1252 bool SSPPresent =
true;
1255 try { SSPrawFragments->size(); }
1257 mf::LogWarning(
"SSPToOffline") <<
"WARNING: Raw SSP data not found in event " <<
event.event();
1262 if(!SSPrawFragments.
isValid()){
1263 mf::LogError(
"SSPToOffline") <<
"Run: " <<
event.run() <<
", SubRun: " <<
event.subRun() <<
", Event: " <<
event.event() <<
" is NOT VALID";
1268 artdaq::Fragments
const& rawFragmentsSSP = *SSPrawFragments;
1269 std::cout<<
"rawFragmentsSSP.size() = "<<rawFragmentsSSP.size()<<
std::endl;
1271 if ( rawFragmentsSSP.size() ) {
1272 const auto& frag(rawFragmentsSSP[0]);
1273 const SSPDAQ::MillisliceHeader* meta=0;
1274 if(frag.hasMetadata())
1276 meta = &(frag.metadata<lbne::SSPFragment::Metadata>()->sliceHeader);
1277 std::cout <<
"=== SSP Metadata, Start time " << meta->startTime <<
", End time " << meta->endTime <<
" Packet length " << meta->length <<
" Number of triggers " << meta->nTriggers <<
"===" <<
std::endl;
1283 for (
size_t fragIndex = 0; fragIndex < rawFragmentsSSP.size(); ++fragIndex) {
1284 const auto& frag(rawFragmentsSSP.at(fragIndex));
1285 const SSPDAQ::MillisliceHeader *meta = 0;
1286 if (frag.hasMetadata()) {
1287 meta = &(frag.metadata<lbne::SSPFragment::Metadata>()->sliceHeader);
1288 std::cout<<fragIndex<<
", "<<meta->endTime<<
std::endl;
1289 if (fragIndex == rawFragmentsSSP.size()-1)
SSPTimeEnd = meta->endTime;
1305 cout <<
"\n id: " <<
fMC_id[i];
1306 cout <<
"\n pdg: " <<
fMC_pdg[i];
1317 cout <<
"Number of Hits Found: " <<
no_hits <<
endl;
1335 #endif // CTree35t_Module float fOpDetPositions_Y[MAX_OPDET]
def analyze(root, level, gtrees, gbranches, doprint)
const TGeoNode * Node() const
Returns the ROOT object describing the detector geometry.
void processHits(const art::Event &evt)
float fOpDetHalfWidths[MAX_OPDET]
Store parameters for running LArG4.
void processCalib(const art::Event &evt)
std::string fHitsModuleLabel
void analyze(const art::Event &evt)
PlaneGeo const & Plane(unsigned int const p, unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified wire.
geo::Length_t DetHalfWidth(geo::TPCID const &tpcid) const
Returns the half width of the active volume of the specified TPC.
Encapsulate the construction of a single cyostat.
TObjArray * fReco_trackPosition
void processMC(const art::Event &evt)
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
geo::WireID WireID() const
Declaration of signal hit object.
std::vector< std::vector< int > > timestamp
Point_t const & LocationAtPoint(size_t i) const
float hit_wireID[MAX_HITS]
The data type to uniquely identify a Plane.
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
std::string fTrackModuleLabel
int hit_channel[MAX_HITS]
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
CryostatID_t Cryostat
Index of cryostat.
Definition of basic raw digits.
void GetCenter(double *xyz, double localz=0.0) const
float Integral() const
Integral under the calibrated signal waveform of the hit, in tick x ADC units.
TObjArray * averageWaveforms
int chit_cryostat[MAX_HITS]
WireID_t Wire
Index of the wire within its plane.
int fRaw_time[MAX_CHANNEL]
int thit_wireID[MAX_HITS]
Int_t fCountOpDetDetected[MAX_OPDET]
SigType_t SignalType(geo::PlaneID const &pid) const
Returns the type of signal on the channels of specified TPC plane.
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
unsigned int Ncryostats() const
Returns the number of cryostats in the detector.
float hit_peakT[MAX_HITS]
float fMC_endMomentum[MAX_TRACKS][4]
std::vector< std::vector< int > > fRaw_wfADC
TTree * fThePhotonTreeDetected
geo::Length_t WirePitch(geo::PlaneID const &planeid) const
Returns the distance between two consecutive wires.
float fOpDetHalfHeights[MAX_OPDET]
Q_EXPORT QTSManip setprecision(int p)
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.
int fPlane_wires[MAX_PLANE]
void processRaw(const art::Event &evt)
float fOpDetPositions_Z[MAX_OPDET]
unsigned int Nchannels() const
Returns the number of TPC readout channels in the detector.
std::string fClusterModuleLabel
TTree * fThePhotonTreeAll
float thit_peakT[MAX_HITS]
View_t View() const
Which coordinate does this plane measure.
Int_t fCountEventDetected
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
QTextStream & reset(QTextStream &s)
unsigned int Nplanes(unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wire planes in the specified TPC.
void reconfigure(fhicl::ParameterSet const &pset)
geo::Length_t DetHalfHeight(geo::TPCID const &tpcid) const
Returns the half height of the active volume of the specified TPC.
#define DEFINE_ART_MODULE(klass)
const OpDetGeo & OpDet(unsigned int iopdet) const
Return the iopdet'th optical detector in the cryostat.
void saveChannelWireMap()
Collect all the RawData header files together.
T get(std::string const &key) const
float fMC_startMomentum[MAX_TRACKS][4]
int chit_channel[MAX_HITS]
bool fMakeOpDetEventsTree
TObjArray * fMC_trackMomentum
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
geo::Length_t DetLength(geo::TPCID const &tpcid) const
Returns the length of the active volume of the specified TPC.
CryostatGeo const & Cryostat(geo::CryostatID const &cryoid) const
Returns the specified cryostat.
int fCalib_channelId[MAX_CHANNEL]
Int_t fCountOpDetAll[MAX_OPDET]
int chit_charge[MAX_HITS]
void processRecoTracks(const art::Event &event)
PlaneID_t Plane
Index of the plane within its TPC.
Declaration of cluster object.
int fPlane_view[MAX_PLANE]
Definition of data types for geometry description.
art::ServiceHandle< geo::Geometry > fGeom
Provides recob::Track data product.
unsigned int NOpDets() const
Number of OpDets in the whole detector.
Detector simulation of raw signals on wires.
unsigned int NTPC(unsigned int cstat=0) const
Returns the total number of TPCs in the specified cryostat.
Encapsulate the geometry of an optical detector.
std::map< int, int > waveformCount
float hit_charge[MAX_HITS]
float thit_charge[MAX_HITS]
float PeakTime() const
Time of the signal peak, in tick units.
std::vector< std::vector< int > > OpChannelToOpDet
double fPlane_wireangle[MAX_PLANE]
std::vector< std::vector< int > > fCalib_wfADC
std::string fOpDetInputModule
std::vector< std::vector< int > > fRaw_wfTDC
std::string fRCERawDataLabel
Encapsulate the construction of a single detector plane.
void processOpDet(const art::Event &event)
int chit_cluster[MAX_HITS]
TObjArray * fMC_trackPosition
double fPlane_wirepitch[MAX_PLANE]
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
std::vector< std::vector< int > > fMC_daughters
object containing MC truth information necessary for making RawDigits and doing back tracking ...
void WireEndPoints(geo::WireID const &wireid, double *xyzStart, double *xyzEnd) const
Fills two arrays with the coordinates of the wire end points.
std::string fSSPRawDataLabel
float fMC_endXYZT[MAX_TRACKS][4]
Declaration of basic channel signal object.
float hit_plane[MAX_HITS]
float chit_peakT[MAX_HITS]
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
TPCID_t TPC
Index of the TPC within its cryostat.
void beginRun(const art::Run &run)
std::string fInstanceName
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
int fRaw_channelId[MAX_CHANNEL]
void processTiming(const art::Event &event)
std::string fRawDigitLabel
bool fMakeDetectedPhotonsTree
int fRaw_charge[MAX_CHANNEL]
raw::ChannelID_t Channel() const
ID of the readout channel the hit was extracted from.
void saveWireGeometry(int plane, int tpc)
std::vector< std::vector< int > > fCalib_wfTDC
int thit_channel[MAX_HITS]
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
int fPlane_type[MAX_PLANE]
QTextStream & endl(QTextStream &s)
unsigned int NAuxDets() const
Returns the number of auxiliary detectors.
int fMC_mother[MAX_TRACKS]
Event finding and building.
float fMC_startXYZT[MAX_TRACKS][4]