Skip to content

Commit ecae9f1

Browse files
authored
Merge pull request #5 from hyperk/feature/PileUpApp
Feature/pile up app
2 parents daf5925 + 87a2a84 commit ecae9f1

20 files changed

+10255
-44
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# binary
66
appWCTESingleEvent
77
appIWCDSingleEvent
8+
appGenPileUpSpill
89

910
# root file
1011
*.root

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,31 @@ Then set up the MDT environment.
2929
source envMDT.sh
3030
cd $MDTROOT/cpp; make clean; make all
3131
cd $MDTROOT/app/utilities/WCRootData; make clean; make all
32-
cd $MDTROOT/app/application; make clean; make appIWCDSingleEvent
32+
cd $MDTROOT/app/application; make clean; make all
3333
cd $MDTROOT
3434
# edit variables properly in run_test_mdt4wcte.sh
3535
bash run_test_mdt4iwcd.sh
3636
```
37+
38+
## IWCD usage
39+
Essentially the same usage but with OD support.
40+
```
41+
# edit variables properly in run_test_mdt4iwcd.sh
42+
bash run_test_mdt4iwcd.sh
43+
```
44+
45+
## IWCD pile-up generation
46+
Example usage
47+
```
48+
$MDTROOT/app/application/appGenPileUpSpill $MDTROOT/example/genPileUpConfig.txt
49+
```
50+
The application generates pile-up events by combining ID neutrino interaction events and beam background events in a spill.
51+
52+
Input variables are:
53+
- `ListIDNuIntFiles`,`ListBeamBkgFiles`: list of WCSim output files for the ID and background events
54+
- `OutFileNamePrefix`: output file name will be something like "OutFileNamePrefix".00000.root
55+
- `MDTParFile`: MDT config file
56+
- `InitialSeed`: Random seed
57+
- `IDNuIntRate`,`BeamBkgRate`: Mean number of ID and background events per spill. In each spill, the actual number of interactions are drawn from a Poisson distribution, and interaction timing according to the bunch structure (see `BeamTiming` class under `app/utilities/WCRootData/`)
58+
- `UseOD`: Process OD hits
59+
- `NumOfSpillsSavedPerFile`, `TotalNumOfSpills`: output spill setup

app/application/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pbuilder_install_headers(${HEADERS})
2828
set(exe_sources
2929
appIWCDSingleEvent.cc
3030
appWCTESingleEvent.cc
31+
appGenPileUpSpill.cc
3132
)
3233

3334
pbuilder_executables(

app/application/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,18 @@ appIWCDSingleEvent: appIWCDSingleEvent.o PMTResponse3inchR12199_02.o
2323
$(LD) $^ $(LDFLAGS) -o $@
2424
@echo "$@ done"
2525

26+
appGenPileUpSpill: appGenPileUpSpill.o PMTResponse3inchR12199_02.o
27+
$(RM) $@
28+
$(LD) $^ $(LDFLAGS) -o $@
29+
@echo "$@ done"
30+
2631
%o::%cc
2732
$(CXX) $(CXXFLAGS) -c $? -o $@
2833

34+
all: appWCTESingleEvent appIWCDSingleEvent appGenPileUpSpill
35+
2936
clean:
3037
$(RM) *.o
3138
$(RM) -f appWCTESingleEvent
3239
$(RM) -f appIWCDSingleEvent
40+
$(RM) -f appGenPileUpSpill

app/application/appGenPileUpSpill.cc

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
#include "WCRootDataPileUpSpill.h"
1111
#include "BeamTiming.h"
1212

13+
// PMT type used for 3-inch PMTs of IWCD/WCTE
14+
#include "PMTResponse3inchR12199_02.h"
15+
1316
std::string fInFileTextIDNuInt = "";
1417
std::string fInFileTextBeamBkg = "";
1518
std::string fOutFileNamePrefix = "";
@@ -19,11 +22,19 @@ int fNumOfSpillsPerFile = 1000;
1922
float fIDNuIntRate = 3.5;
2023
float fBeamBkgRate = 7.5;
2124
int fTotalNumofSpills = 10000;
25+
int fUseOD = 0;
2226

2327
void ReadConfiguration(const char*);
2428

2529
int main(int argc, char **argv)
2630
{
31+
if (argc==1)
32+
{
33+
std::cout<<" ** Please specify input config file ** "<<std::endl;
34+
std::cout<<" ** Usage: appGenPileUpSpill config_file ** "<<std::endl;
35+
return 0;
36+
}
37+
2738
std::string ConfigFileName = argv[1];
2839
ReadConfiguration(argv[1]);
2940

@@ -39,8 +50,20 @@ int main(int argc, char **argv)
3950
const int seed_beamtiming = rndm->Integer(1000000);
4051
delete rndm; rndm = 0;
4152

53+
// IWCD PMT type for ID and OD
54+
int NPMTType = !fUseOD ? 1 : 2 ;
55+
vector<string> fPMTType(NPMTType);
56+
fPMTType[0] = "PMT3inchR12199_02";
57+
if (fUseOD>0) fPMTType[1] = "PMT3inchR12199_02_OD";
58+
4259
// Will be manaing marging true hits and digitizing merged true hits
4360
MDTManager *MDT = new MDTManager(seed_mdt);
61+
MDT->RegisterPMTType(fPMTType[0], new PMTResponse3inchR12199_02());
62+
if (fUseOD) MDT->RegisterPMTType(fPMTType[1], new PMTResponse3inchR12199_02());
63+
64+
vector<string> listWCRootEvt(NPMTType);
65+
listWCRootEvt[0] = "wcsimrootevent";
66+
if (fUseOD) listWCRootEvt[1] = "wcsimrootevent_OD";
4467

4568
// Manage input files for ID interactions
4669
WCRootDataIDNuInt *daIDNuInt = new WCRootDataIDNuInt();
@@ -56,12 +79,13 @@ int main(int argc, char **argv)
5679
daBeamBkg->SetSeed(seed_beambkg);
5780

5881
// Will be used to extract file ID number
59-
daIDNuInt->SetNDigitsFileIDNumber(5);
60-
daBeamBkg->SetNDigitsFileIDNumber(6);
82+
// KMTsui: I don't have it has real usage
83+
// daIDNuInt->SetNDigitsFileIDNumber(5);
84+
// daBeamBkg->SetNDigitsFileIDNumber(6);
6185

6286
// Load input files from text file
63-
daIDNuInt->LoadFiles(fInFileTextIDNuInt.c_str());
64-
daBeamBkg->LoadFiles(fInFileTextBeamBkg.c_str());
87+
daIDNuInt->LoadFiles(fInFileTextIDNuInt.c_str(),listWCRootEvt);
88+
daBeamBkg->LoadFiles(fInFileTextBeamBkg.c_str(),listWCRootEvt);
6589

6690
// Set number of ID interactions per spill
6791
daIDNuInt->SetInteractionRate(fIDNuIntRate);
@@ -80,7 +104,7 @@ int main(int argc, char **argv)
80104
daPileUp->SetFileNameForCopyTree(daIDNuInt->GetCurrentInputFileName());
81105

82106
// Create output file. Its name will be something like "OutFileNamePrefix".00000.root
83-
daPileUp->CreateTree(fOutFileNamePrefix.c_str());
107+
daPileUp->CreateTree(fOutFileNamePrefix.c_str(),listWCRootEvt);
84108

85109
float nuIntTime; // interaction time
86110
int nuIntBunch; // bunch id number
@@ -107,7 +131,8 @@ int main(int argc, char **argv)
107131
bt->DrawInteractionTime(nuIntTime, nuIntBunch);
108132

109133
// Add true hits of this interaction to MDT
110-
daIDNuInt->AddTrueHitsToMDT(MDT, nuIntTime);
134+
for(int k=0; k<NPMTType; k++)
135+
daIDNuInt->AddTrueHitsToMDT(MDT->GetHitTubeCollection(fPMTType[k]), MDT->GetPMTResponse(fPMTType[k]), nuIntTime, k);
111136

112137
// Add information about this interaction
113138
daPileUp->AddInteraction(daIDNuInt, nuIntTime, nuIntBunch);
@@ -119,18 +144,24 @@ int main(int argc, char **argv)
119144
daBeamBkg->Next();
120145

121146
bt->DrawInteractionTime(nuIntTime, nuIntBunch);
122-
daBeamBkg->AddTrueHitsToMDT(MDT, nuIntTime);
147+
for(int k=0; k<NPMTType; k++)
148+
daBeamBkg->AddTrueHitsToMDT(MDT->GetHitTubeCollection(fPMTType[k]), MDT->GetPMTResponse(fPMTType[k]), nuIntTime, k);
123149
daPileUp->AddInteraction(daBeamBkg, nuIntTime, nuIntBunch);
124150
}
125151

126152
// Now all the true hits have been merged into one spill
127153
// Add dark noise hits, and then make digitized hits
128-
MDT->DoAddDark();
129-
MDT->DoDigitize();
130-
MDT->DoTrigger();
154+
for(int j=0; j<NPMTType; j++)
155+
{
156+
MDT->DoAddDark(fPMTType[j]);
157+
MDT->DoDigitize(fPMTType[j]);
158+
MDT->DoTrigger(fPMTType[j]);
159+
160+
// Add the resultant digitized hits to the output
161+
TriggerInfo *ti = MDT->GetTriggerInfo(fPMTType[j]);
162+
daPileUp->AddDigiHits(MDT->GetHitTubeCollection(fPMTType[j]), ti, i, j);
163+
}
131164

132-
// Add the resultant digitized hits to the output
133-
daPileUp->AddDigiHits(MDT);
134165
daPileUp->FillTree();
135166

136167
// Clear all the true and digitized hits of this spill for the next spill
@@ -162,5 +193,6 @@ void ReadConfiguration(const char *filename)
162193
Conf->GetValue<float>("IDNuIntRate", fIDNuIntRate);
163194
Conf->GetValue<float>("BeamBkgRate", fBeamBkgRate);
164195
Conf->GetValue<int>("TotalNumOfSpills", fTotalNumofSpills);
196+
Conf->GetValue<int>("UseOD", fUseOD);
165197
Conf->Finalize();
166198
}

app/utilities/WCRootData/include/WCRootDataBeamBkg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class WCRootDataBeamBkg : public WCRootDataNuInt
1111
WCRootDataBeamBkg();
1212
virtual ~WCRootDataBeamBkg();
1313

14-
void LoadFiles(const char *);
14+
void LoadFiles(const char *, const std::vector<string> &v=vector<string>());
1515
float GetEnergyDepositionInOD() const { return fEdepoOD; }
1616

1717
private :

app/utilities/WCRootData/include/WCRootDataIDNuInt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class WCRootDataIDNuInt : public WCRootDataNuInt
1212
WCRootDataIDNuInt();
1313
virtual ~WCRootDataIDNuInt();
1414

15-
void LoadFiles(const char*);
15+
void LoadFiles(const char*, const std::vector<string> &v=vector<string>());
1616
void SetInteractionInformation(PileUpSpill_t*) const;
1717

1818
private :

app/utilities/WCRootData/include/WCRootDataNuInt.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class WCRootDataNuInt : public WCRootData
2222
virtual ~WCRootDataNuInt();
2323

2424
void SetSeed(const int i){ fRnd->SetSeed(i); }
25-
void LoadFiles(const char*);
25+
void LoadFiles(const char*, const std::vector<string> &v=vector<string>());
2626
virtual bool Next();
2727

2828
void SetNDigitsFileIDNumber(int i){ fNDigitsFileIdNum = i; }
@@ -36,6 +36,8 @@ class WCRootDataNuInt : public WCRootData
3636
virtual float GetEnergyDepositionInOD() const { return 0.; }
3737
virtual void SetInteractionInformation(PileUpSpill_t*) const {};
3838

39+
void SetHasFriend(bool val) {fHasFriend=val;}
40+
3941
protected:
4042
int GetFileIdNumber(const char*, const char *prefix="wcsim.");
4143

@@ -58,5 +60,6 @@ class WCRootDataNuInt : public WCRootData
5860
int fFileIdNum;
5961
int fNDigitsFileIdNum;
6062
float fIntRate;
63+
std::vector<string> fWCRootEvtList;
6164
};
6265
#endif

app/utilities/WCRootData/include/WCRootDataPileUpSpill.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class WCRootDataPileUpSpill : public WCRootData
2727

2828
// For writing
2929
// void SetOutFilePrefix(const char *f){ fOutFilePrefix = TString(f); }
30-
void CreateTree(const char *f=0);
30+
void CreateTree(const char *f=0, const vector<string> &v=vector<string>());
3131
void FillTree();
3232
void WriteTree();
3333
void AddInteraction(const WCRootDataNuInt*, float offset_time=0., int bunch_id=99999);

app/utilities/WCRootData/src/WCRootData.cc

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@ void WCRootData::AddTrueHitsToMDT(HitTubeCollection *hc, PMTResponse *pr, float
8383
if( truetime<0. ){ continue; }
8484
if( aHitTime->GetParentID()<0 ){ continue; }
8585

86-
TrueHit *th = new TrueHit(truetime, aHitTime->GetParentID());
86+
TrueHit *th = new TrueHit(truetime+intTime, aHitTime->GetParentID());
8787

8888
for(int k=0; k<3; k++){ th->SetPosition(k, aHitTime->GetPhotonEndPos(k)); }
8989
for(int k=0; k<3; k++){ th->SetDirection(k, aHitTime->GetPhotonEndDir(k)); }
9090
for(int k=0; k<3; k++){ th->SetStartDirection(k, aHitTime->GetPhotonStartDir(k)); }
9191

92-
th->SetStartTime(aHitTime->GetPhotonStartTime());
92+
th->SetStartTime(aHitTime->GetPhotonStartTime()+intTime);
9393
for(int k=0; k<3; k++){ th->SetStartPosition(k, aHitTime->GetPhotonStartPos(k)); }
9494
if( !pr->ApplyDE(th) ){ continue; }
9595

@@ -198,6 +198,56 @@ void WCRootData::AddDigiHits(MDTManager *mdt, int eventID, int iPMT)
198198
void WCRootData::AddDigiHits(HitTubeCollection *hc, TriggerInfo *ti, int eventID, int iPMT)
199199
{
200200
WCSimRootTrigger* anEvent = fSpEvt[iPMT]->GetTrigger(0);
201+
// Save raw hits
202+
// container for photon info
203+
std::vector<double> truetime;
204+
std::vector<int> primaryParentID;
205+
std::vector<float> photonStartTime;
206+
std::vector<TVector3> photonStartPos;
207+
std::vector<TVector3> photonEndPos;
208+
std::vector<TVector3> photonStartDir;
209+
std::vector<TVector3> photonEndDir;
210+
for(hc->Begin(); !hc->IsEnd(); hc->Next())
211+
{
212+
// Get tube ID
213+
HitTube *aPH = &(*hc)();
214+
int tubeID = aPH->GetTubeID();
215+
int mPMTID = aPH->GetmPMTID();
216+
int mPMT_PMTID = aPH->GetmPMT_PMTID();
217+
218+
219+
const int NPE = aPH->GetNRawPE();
220+
const vector<TrueHit*> PEs = aPH->GetPhotoElectrons();
221+
for(int iPE=0; iPE<NPE; iPE++)
222+
{
223+
truetime.push_back(PEs[iPE]->GetTime());
224+
primaryParentID.push_back(PEs[iPE]->GetParentId());
225+
photonStartTime.push_back(PEs[iPE]->GetStartTime());
226+
photonStartPos.push_back(TVector3(PEs[iPE]->GetStartPosition(0),PEs[iPE]->GetStartPosition(1),PEs[iPE]->GetStartPosition(2)));
227+
photonEndPos.push_back(TVector3(PEs[iPE]->GetPosition(0),PEs[iPE]->GetPosition(1),PEs[iPE]->GetPosition(2)));
228+
photonStartDir.push_back(TVector3(PEs[iPE]->GetStartDirection(0),PEs[iPE]->GetStartDirection(1),PEs[iPE]->GetStartDirection(2)));
229+
photonEndDir.push_back(TVector3(PEs[iPE]->GetDirection(0),PEs[iPE]->GetDirection(1),PEs[iPE]->GetDirection(2)));
230+
}
231+
232+
anEvent->AddCherenkovHit(tubeID,
233+
mPMTID,
234+
mPMT_PMTID,
235+
truetime,
236+
primaryParentID,
237+
photonStartTime,
238+
photonStartPos,
239+
photonEndPos,
240+
photonStartDir,
241+
photonEndDir);
242+
243+
truetime.clear();
244+
primaryParentID.clear();
245+
photonStartTime.clear();
246+
photonStartPos.clear();
247+
photonEndPos.clear();
248+
photonStartDir.clear();
249+
photonEndDir.clear();
250+
}
201251
const int nTriggers = ti->GetNumOfTrigger();
202252
for(int iTrig=0; iTrig<nTriggers; iTrig++)
203253
{
@@ -237,14 +287,13 @@ void WCRootData::AddDigiHits(HitTubeCollection *hc, TriggerInfo *ti, int eventID
237287
{
238288
HitTube *aPH = &(*hc)();
239289
int tubeID = aPH->GetTubeID();
290+
int mPMTID = aPH->GetmPMTID();
291+
int mPMT_PMTID = aPH->GetmPMT_PMTID();
240292
int nCount = 0;
241293
for(int i=0; i<aPH->GetNDigiHits(); i++)
242294
{
243295
float t = aPH->GetTimeDigi(i);
244296

245-
// Need to be updated
246-
int mPMT_module_id = 0;
247-
int mPMT_pmt_id = 0;
248297
if( t>=tWinLowEdge && t<=tWinUpEdge )
249298
{
250299
bool doFill = false;
@@ -262,8 +311,8 @@ void WCRootData::AddDigiHits(HitTubeCollection *hc, TriggerInfo *ti, int eventID
262311
anEvent->AddCherenkovDigiHit(q,
263312
t,
264313
tubeID,
265-
mPMT_module_id,
266-
mPMT_pmt_id,
314+
mPMTID,
315+
mPMT_PMTID,
267316
true_pe_comp);
268317
nHits += 1;
269318
sumQ += q;
@@ -477,11 +526,15 @@ void WCRootData::SetTubes(HitTubeCollection *hc, const int iPMT)
477526
const WCSimRootPMT *tube = !isOD.at(iPMT) ? fWCGeom->GetPMTPtr(i, bool(iPMT)) : fWCGeom->GetODPMTPtr(i) ;
478527

479528
const int tubeID = tube->GetTubeNo();
529+
const int mPMTID = tube->GetmPMTNo();
530+
const int mPMT_PMTID = tube->GetmPMT_PMTNo();
480531
hc->AddHitTube(tubeID);
481532
for(int j=0; j<3; j++)
482533
{
483534
(&(*hc)[tubeID])->SetPosition(j, tube->GetPosition(j));
484535
(&(*hc)[tubeID])->SetOrientation(j, tube->GetOrientation(j));
485536
}
537+
(&(*hc)[tubeID])->SetmPMTID(mPMTID);
538+
(&(*hc)[tubeID])->SetmPMT_PMTID(mPMT_PMTID);
486539
}
487540
}

0 commit comments

Comments
 (0)