ARTEMIS-CRIB
 
Loading...
Searching...
No Matches
TTimingChargeAllMappingProcessor.cc
Go to the documentation of this file.
1/**
2 * @file TTimingChargeAllMappingProcessor.cc
3 * @brief from TTimingChargeMappingProcessor, both E and T
4 * @author Kodai Okawa <okawa@cns.s.u-tokyo.ac.jp>
5 * @date 2022?
6 * @note last modified: 2024-08-23 20:58:00
7 * @details
8 */
9
11
12#include "TTimingChargeData.h"
13#include "constant.h"
14#include <TCategorizedData.h>
15#include <TRawDataTimingCharge.h>
16#include <TRawTimingWithEdge.h>
17
19
21
22// Default constructor
24 : fPlastic(nullptr) {
25 RegisterInputCollection("InputCollection", "rawdata object returned by TRIDFEventStore",
26 fInputColName, TString("catdata"),
27 &fCategorizedData, "art::TCategorizedData");
28 RegisterOutputCollection("OutputCollection", "output collection name",
29 fOutputColName, TString("plastic_raw"),
30 &fPlastic, "TClonesArray", "art::TTimingChargeData");
31 RegisterProcessorParameter("CatID", "Category ID of plastic", fCatID, 21);
32 RegisterProcessorParameter("ChargeType", "0: V1190 width (default), 1: QDC (V792 etc.), 2: paired time and charge (hinp)",
33 fChargeType, 0);
34 RegisterProcessorParameter("ChargeTypeID", "data type id for charge information (valid when ChargeType != (0 or 2) , default: 2)",
35 fChargeTypeID, 2);
36 RegisterProcessorParameter("TimingTypeID", "data type id for timing information (default: 1)",
37 fTimingTypeID, 1);
38 RegisterProcessorParameter("TrailingComesFirst", "0: Leading->Trailing (default), 1: Trailing->Leading (for QTC etc.)",
39 fTrailingComesFirst, kFALSE);
40 RegisterProcessorParameter("Sparse", "hit will be inserted at the index corresponding to its id if sparse is 0, otherwize hit will be added ordinaly (default: 1)",
41 fIsSparse, kTRUE);
42}
43
47
49 const TString &chargeTypeStr =
50 TString::Format("ChargeType: %d", fChargeType) +
51 (fChargeType ? TString::Format(", ChargeTypeID: %d", fChargeTypeID) : "");
52
53 Info("Init", "CatID: %d, TimingTypeID: %d => %s",
55 Info("Init", "%s", chargeTypeStr.Data());
56 Info("Init", "TrailingComesFirst: %d", fTrailingComesFirst);
57
58 if (fIsSparse) {
59 Info("Init", "This processor treat only not sparse data");
60 fIsSparse = 0;
61 };
62}
63
65 fPlastic->Clear("C");
66
67 const TObjArray *const cat = (*fCategorizedData)->FindCategory(fCatID);
68 if (!cat)
69 return;
70
71 for (Int_t i = 0, n = cat->GetEntriesFast(); i != n; ++i) {
72 const TObjArray *const det = static_cast<TObjArray *>(cat->At(i));
73 const TObjArray *const tArray = static_cast<TObjArray *>(det->At(fTimingTypeID));
74 // if (!tArray || tArray->IsEmpty()) continue;
75 if (fChargeType == kWIDTH) {
76 MapEdgedTime(tArray);
77 } else if (fChargeType == kHINP) {
78 MapPairedTimeCharge(tArray);
79 } else /* if (fChargeType == kQDC) */ {
80 const TObjArray *const qArray = static_cast<TObjArray *>(det->At(fChargeTypeID));
81 MapTimeCharge(tArray, qArray);
82 }
83 }
84
85 if (fIsSparse) {
86 // sort data in the same event in ascending order of timing
87 TTimingChargeData::SetSortType(TTimingChargeData::kTiming);
88 TTimingChargeData::SetSortOrder(TTimingChargeData::kASC);
89 fPlastic->Sort();
90 fPlastic->Compress();
91 } else {
92 for (Int_t i = 0, n = fPlastic->GetEntriesFast(); i != n; ++i) {
93 fPlastic->ConstructedAt(i);
94 }
95 }
96}
97
99 if (!tArray || tArray->IsEmpty())
100 return;
101
102 TTimingChargeData *data = nullptr;
103 for (Int_t iHit = 0, nHit = tArray->GetEntriesFast(); iHit != nHit; ++iHit) {
104 const TRawTimingWithEdge *const hit = static_cast<TRawTimingWithEdge *>(tArray->At(iHit));
105 // if (!hit) continue;
106
107 if (hit->IsLeading() != fTrailingComesFirst) {
108 // "Leading" edge
109 const Int_t detID = hit->GetDetID();
110 const Int_t idx = fIsSparse ? fPlastic->GetEntriesFast() : detID;
111 data = static_cast<TTimingChargeData *>(fPlastic->ConstructedAt(idx));
112 if (IsValid(data->GetDetID()))
113 continue;
114
115 data->SetDetID(detID);
116 const Double_t tLeading = hit->GetTiming();
117 data->SetTiming(tLeading);
118 } else if (data) {
119 // "Trailing" edge after "Leading" one
120 const Double_t tLeading = data->GetTiming();
121 const Double_t tTrailing = hit->GetTiming();
122 const Double_t charge = tTrailing - tLeading;
123
124 data->SetCharge(charge);
125 data = nullptr;
126 } else {
127 // consecutive "Trailing" edge
128 // thought to be abnormal
129 }
130 }
131}
132
133void TTimingChargeAllMappingProcessor::MapTimeCharge(const TObjArray *tArray, const TObjArray *qArray) {
134 if ((!tArray || tArray->IsEmpty()) && (!qArray || qArray->IsEmpty()))
135 return;
136
137 TTimingChargeData *data;
138
139 Bool_t data_flag = false;
140 if (tArray && !(tArray->IsEmpty())) {
141 const TRawDataObject *const tHit = static_cast<TRawDataObject *>(tArray->At(0));
142
143 const Int_t detID = tHit->GetDetID();
144 if (IsValid(detID)) {
145 const Int_t idx = fIsSparse ? fPlastic->GetEntriesFast() : detID;
146 data = static_cast<TTimingChargeData *>(fPlastic->ConstructedAt(idx));
147
148 if (IsValid(data->GetDetID()))
149 return; // take only the first hit
150 data->SetDetID(detID);
151 data->SetTiming(tHit->GetValue());
152
153 data_flag = true;
154 }
155 }
156 if (qArray && !(qArray->IsEmpty())) {
157 const TRawTiming *const qHit = static_cast<TRawTiming *>(qArray->At(0));
158 if (!data_flag) {
159 const Int_t detID = qHit->GetDetID();
160 const Int_t idx = fIsSparse ? fPlastic->GetEntriesFast() : detID;
161 data = static_cast<TTimingChargeData *>(fPlastic->ConstructedAt(idx));
162
163 if (IsValid(data->GetDetID()))
164 return; // take only the first hit
165 data->SetDetID(detID);
166 data->SetCharge(qHit->GetValue());
167
168 data_flag = true;
169 } else {
170 data->SetCharge(qHit->GetValue());
171 }
172 }
173}
174
176 if (!tArray || tArray->IsEmpty())
177 return;
178
179 TTimingChargeData *data = nullptr;
180 for (Int_t iHit = 0, nHit = tArray->GetEntriesFast(); iHit != nHit; ++iHit) {
181 const TRawDataTimingCharge *const hit = static_cast<TRawDataTimingCharge *>(tArray->At(iHit));
182
183 const Int_t detID = hit->GetDetID();
184 const Int_t idx = fIsSparse ? fPlastic->GetEntriesFast() : detID;
185 data = static_cast<TTimingChargeData *>(fPlastic->ConstructedAt(idx));
186 if (IsValid(data->GetDetID()))
187 continue;
188
189 data->SetDetID(detID);
190 const Double_t timing = hit->GetTiming();
191 const Double_t charge = hit->GetCharge();
192 data->SetTiming(timing);
193 data->SetCharge(charge);
194 }
195}
ClassImp(TTimingChargeAllMappingProcessor)
from TTimingChargeMappingProcessor, both E and T
void MapTimeCharge(const TObjArray *, const TObjArray *)
return to the guide