38 #include <AIDA/AIDA.h>
46 CCalAnalysis::CCalAnalysis() :analysisFactory(0), tree(0), tuple(0),
energy(0) {
48 for (
int i=0; i<28; i++) {hcalE[i] = 0;}
49 for (
int i=0; i<70; i++) {lateralProfile[i] = 0;}
50 for (
int i=0; i<49; i++) {ecalE[i] = 0;}
51 for (
int i=0; i<numberOfTimeSlices; i++) {timeHist[i] = 0;}
52 for (
int i=0; i<2; i++) {timeProfile[i] = 0;}
54 analysisFactory = AIDA_createAnalysisFactory();
55 if (analysisFactory) {
57 AIDA::ITreeFactory* treeFactory = analysisFactory->createTreeFactory();
61 const char* opFileptr = getenv(
"CCAL_FILENAME");
63 if (opFileptr) opFilestr = opFileptr;
64 G4cout <<
"********************************************" <<
G4endl
65 <<
"* o/p file on " << opFilestr <<
G4endl
66 <<
"********************************************" <<
G4endl
68 bool readOnly =
false;
69 bool createNew =
true;
70 tree = treeFactory->create(opFilestr,
"hbook", readOnly,createNew);
73 AIDA::ITupleFactory* tupleFactory = analysisFactory->createTupleFactory(*tree);
77 for (
int i=0; i<28; i++) {
78 tag2 = tag +
" hcal" + i +
",";
81 for (
int i=0; i<49; i++) {
82 tag2 = tag +
" ecal" + i +
",";
85 tag2 = tag +
" ELAB, XPOS, YPOS, ZPOS";
86 tag = tag2 +
", EDEP, EDEC, EDHC";
88 tuple = tupleFactory->create(
"1",
"Event info", tag);
96 AIDA::IHistogramFactory* histoFactory =
97 analysisFactory->createHistogramFactory(*tree);
100 char id[4], ntupletag[50];
102 for (
int i = 0; i<28; i++) {
103 sprintf(
id,
"%d",i+100);
104 sprintf(ntupletag,
"Energy Deposit in Hcal Layer%d in GeV",i);
105 hcalE[i] = histoFactory->createHistogram1D(
id, ntupletag, 100, 0., 1.0);
108 for (
int i = 0; i<49; i++) {
109 sprintf(
id,
"%d",i+200);
110 sprintf(ntupletag,
"Energy Deposit in Ecal Tower%d in GeV",i);
111 ecalE[i] = histoFactory->createHistogram1D(
id, ntupletag, 100, 0., 100.0);
114 energy = histoFactory->createHistogram1D(
"4000",
"Total energy deposited in GeV",
118 for (
int i=0; i<numberOfTimeSlices; i++){
119 sprintf(
id,
"%d",i+300);
120 sprintf(ntupletag,
"Time slice %d nsec energy profile in GeV",i);
121 timeHist[i] = histoFactory->createHistogram1D(
id, ntupletag, 100, 0., 100.0);
125 for (
int i = 0; i<70; i++) {
126 sprintf(
id,
"%d",i+500);
127 sprintf(ntupletag,
"Lateral energy profile at %d cm in GeV",i);
128 lateralProfile[i] = histoFactory->createHistogram1D(
id, ntupletag, 100, 0., 10.0);
132 timeProfile[0] = histoFactory->createHistogram1D(
"901",
"Time Profile in Sensitive Detector", 200, 0., 200.);
133 timeProfile[1] = histoFactory->createHistogram1D(
"902",
"Time Profile in Sensitive+Passive", 200, 0., 200.);
147 CCalAnalysis::~CCalAnalysis() {
155 void CCalAnalysis::Finish() {
160 if (analysisFactory) {
161 delete analysisFactory;
166 CCalAnalysis* CCalAnalysis::getInstance() {
173 void CCalAnalysis::InsertEnergyHcal(
float* v) {
175 double totalFilledEnergyHcal = 0.0;
177 for (
int i=0; i<28; i++) {
182 G4cout <<
"Fill Hcal histo " << i <<
" with " << x <<
G4endl;
183 totalFilledEnergyHcal += x;
188 G4cout <<
"CCalAnalysis::InsertEnergyHcal: Total filled Energy Hcal histo "
189 << totalFilledEnergyHcal <<
G4endl;
195 void CCalAnalysis::InsertEnergyEcal(
float* v) {
197 double totalFilledEnergyEcal = 0.0;
199 for (
int i=0; i<49; i++) {
204 G4cout <<
"Fill Ecal histo " << i <<
" with " << x <<
G4endl;
205 totalFilledEnergyEcal += x;
210 G4cout <<
"CCalAnalysis::InsertEnergyEcal: Total filled Energy Ecal histo "
211 << totalFilledEnergyEcal <<
G4endl;
217 void CCalAnalysis::InsertLateralProfile(
float* v) {
219 double totalFilledProfileHcal = 0.0;
221 for (
int i=0; i<70; i++) {
222 if (lateralProfile[i]) {
224 lateralProfile[i]->fill(x);
226 G4cout <<
"Fill Profile Hcal histo " << i <<
" with " << x <<
G4endl;
227 totalFilledProfileHcal += x;
232 G4cout <<
"CCalAnalysis::InsertLateralProfile: Total filled Profile Hcal"
233 <<
" histo " << totalFilledProfileHcal <<
G4endl;
239 void CCalAnalysis::InsertEnergy(
float v) {
244 G4cout <<
"CCalAnalysis::InsertEnergy: Fill Total energy Hcal histo with "
252 void CCalAnalysis::InsertTime(
float* v) {
254 double totalFilledTimeProfile = 0.0;
256 for (
int j=0; j<numberOfTimeSlices; j++) {
259 timeHist[j]->fill(x);
261 G4cout <<
"Fill Time slice histo " << j <<
" with " << x <<
G4endl;
262 totalFilledTimeProfile += x;
265 if (timeProfile[1]) {
268 timeProfile[1]->fill(t,x);
270 G4cout <<
"Fill Time profile histo 1 with " << t <<
" " << x <<
G4endl;
275 G4cout <<
"CCalAnalysis::InsertTime: Total filled Time profile histo "
276 << totalFilledTimeProfile <<
G4endl;
282 void CCalAnalysis::InsertTimeProfile(
int hit,
double time,
double edep) {
284 if (timeProfile[0]) {
285 timeProfile[0]->fill(time,edep);
287 G4cout <<
"CCalAnalysis:: Fill Time Profile with Hit " << hit
288 <<
" Edeposit " << edep <<
" Gev at " << time <<
" ns" <<
G4endl;
296 void CCalAnalysis::setNtuple(
float* hcalE,
float* ecalE,
float elab,
297 float x,
float y,
float z,
float edep,
298 float edec,
float edhc) {
302 for (
int i=0; i<28; i++) {
303 sprintf (tag,
"hcal%d", i);
304 tuple->fill(tuple->findColumn(tag),hcalE[i]);
306 for (
int i=0; i<49; i++) {
307 sprintf (tag,
"ecal%d", i);
308 tuple->fill(tuple->findColumn(tag),ecalE[i]);
310 tuple->fill(tuple->findColumn(
"ELAB"),elab);
311 tuple->fill(tuple->findColumn(
"XPOS"),x);
312 tuple->fill(tuple->findColumn(
"YPOS"),y);
313 tuple->fill(tuple->findColumn(
"ZPOS"),
z);
314 tuple->fill(tuple->findColumn(
"EDEP"),edep);
315 tuple->fill(tuple->findColumn(
"EDEC"),edec);
316 tuple->fill(tuple->findColumn(
"EDHC"),edhc);
330 void CCalAnalysis::BeginOfRun(
G4int ) {
344 for (
int i=0; i<numberOfTimeSlices; i++) {
345 if (timeHist[i]) timeHist[i]->reset();
352 void CCalAnalysis::EndOfRun(
G4int ) {
363 void CCalAnalysis::EndOfEvent(
G4int flag) {
368 if (
energy->allEntries() == 0 ) {
370 }
else if (
energy->allEntries() ==
energy->extraEntries() ) {
376 for (
int i=0; i<28; i++) {
378 if ( hcalE[i]->allEntries() == 0 ) {
380 }
else if ( hcalE[i]->allEntries() == hcalE[i]->extraEntries() ) {
381 G4cout <<
"EXTRA entries only HISTO hcal " << i <<
G4endl;
387 for (
int i=0; i<70; i++) {
388 if ( lateralProfile[i] ) {
389 if ( lateralProfile[i]->allEntries() == 0 ) {
391 }
else if ( lateralProfile[i]->allEntries() ==
392 lateralProfile[i]->extraEntries() ) {
393 G4cout <<
"EXTRA entries only HISTO lateralProfile " << i <<
G4endl;
396 G4cout <<
"UNDEFINED HISTO lateralProfile " << i <<
G4endl;
399 for (
int i=0; i<49; i++) {
401 if ( ecalE[i]->allEntries() == 0 ) {
403 }
else if ( ecalE[i]->allEntries() == ecalE[i]->extraEntries() ) {
404 G4cout <<
"EXTRA entries only HISTO ecal " << i <<
G4endl;
410 for (
int i=0; i<numberOfTimeSlices; i++) {
412 if ( timeHist[i]->allEntries() == 0 ) {
414 }
else if ( timeHist[i]->allEntries() == timeHist[i]->extraEntries() ) {
415 G4cout <<
"EXTRA entries only HISTO timeHist " << i <<
G4endl;
G4GLOB_DLL std::ostream G4cout
G4double energy(const ThreeVector &p, const G4double m)
static MCTruthManager * instance