00001
00002
00003
00004
00005
00006
00008
00009 #include "AnalysisNtuples/Module/ANtpInfoObjectFillerBeam.h"
00010 #include "MessageService/MsgService.h"
00011 #include "AnalysisNtuples/ANtpTruthInfoBeam.h"
00012 #include "AnalysisNtuples/ANtpBeamInfo.h"
00013 #include "StandardNtuple/NtpStRecord.h"
00014 #include "CandNtupleSR/NtpSRRecord.h"
00015 #include "CandNtupleSR/NtpSREvent.h"
00016 #include "CandNtupleSR/NtpSRStrip.h"
00017 #include "CandNtupleSR/NtpSRTrack.h"
00018 #include "CandNtupleSR/NtpSRShower.h"
00019 #include "MCNtuple/NtpMCRecord.h"
00020 #include "MCNtuple/NtpMCTruth.h"
00021 #include "MCNtuple/NtpMCStdHep.h"
00022 #include "DatabaseInterface/DbiResultPtr.h"
00023 #include "BField/BfieldCoilCurrent.h"
00024 #include "BeamDataUtil/BDSpillAccessor.h"
00025 #include "BeamDataUtil/BeamMonSpill.h"
00026 #include "BeamDataNtuple/NtpBDLiteRecord.h"
00027 #include "SpillTiming/SpillTimeFinder.h"
00028 #include "SpillTiming/SpillServerMon.h"
00029 #include "SpillTiming/SpillServerMonFinder.h"
00030 #include "TStopwatch.h"
00031 #include "Conventions/BeamType.h"
00032 #include <cassert>
00033 #include <algorithm>
00034
00035 using namespace BeamType;
00036
00037 ClassImp(ANtpInfoObjectFillerBeam)
00038
00039 CVSID("$Id: ANtpInfoObjectFillerBeam.cxx,v 1.40 2010/01/19 18:10:24 tinti Exp $");
00040
00041
00042 ANtpInfoObjectFillerBeam::ANtpInfoObjectFillerBeam()
00043 {
00044
00045 fSpillAna = new BMSpillAna();
00046
00047 fSpillAna->UseDatabaseCuts();
00048
00049 MSG("ANtpInfoObjectFillerBeam", Msg::kDebug) << "ANtpInfoObjectFillerBeam::Constructor" << endl;
00050
00051 }
00052
00053
00054 ANtpInfoObjectFillerBeam::ANtpInfoObjectFillerBeam(Detector::Detector_t detector) :
00055 ANtpInfoObjectFiller(detector)
00056 {
00057
00058 fSpillAna = new BMSpillAna();
00059
00060 fSpillAna->UseDatabaseCuts();
00061
00062 MSG("ANtpInfoObjectFillerBeam", Msg::kDebug) << "ANtpInfoObjectFillerBeam::Constructor" << endl;
00063
00064 }
00065
00066
00067 ANtpInfoObjectFillerBeam::~ANtpInfoObjectFillerBeam()
00068 {
00069
00070 delete fSpillAna;
00071 MSG("ANtpInfoObjectFillerBeam", Msg::kDebug) << "ANtpInfoObjectFillerBeam::Destructor" << endl;
00072
00073 }
00074
00075
00076
00077 void ANtpInfoObjectFillerBeam::FillBeamInformation(VldTimeStamp &timeStamp,
00078 Detector::Detector_t det,
00079 SimFlag::SimFlag_t dataType,
00080 ANtpBeamInfo *beamInfo)
00081 {
00082
00083 VldContext vldc(det, dataType, timeStamp);
00084
00085 beamInfo->Reset();
00086
00087
00088
00089
00090
00091
00092
00093
00094 if(dataType == SimFlag::kData){
00095
00096 BDSpillAccessor& spillAccess = BDSpillAccessor::Get();
00097
00098 double x = 0.;
00099 double y = 0.;
00100 double xrms = 0.;
00101 double yrms = 0.;
00102
00103
00104 const BeamMonSpill &spillInfo = *(spillAccess.LoadSpill(timeStamp));
00105 fSpillAna->SetSpill(spillInfo);
00106 spillInfo.BpmAtTarget(x,y,xrms,yrms);
00107
00108 beamInfo->tor101 = spillInfo.fTor101;
00109 beamInfo->tr101d = spillInfo.fTr101d;
00110 beamInfo->tortgt = spillInfo.fTortgt;
00111 beamInfo->trtgtd = spillInfo.fTrtgtd;
00112 beamInfo->hornCurrent = spillInfo.fHornCur;
00113 beamInfo->targetBPMX = x;
00114 beamInfo->targetBPMY = y;
00115 beamInfo->profileWidthX = spillInfo.fProfWidX;
00116 beamInfo->profileWidthY = spillInfo.fProfWidY;
00117 beamInfo->hadronIntensity = spillInfo.fHadInt;
00118 beamInfo->muonIntensity1 = spillInfo.fMuInt1;
00119 beamInfo->muonIntensity2 = spillInfo.fMuInt2;
00120 beamInfo->muonIntensity3 = spillInfo.fMuInt3;
00121 beamInfo->beamType = (Int_t)( spillInfo.BeamType() );
00122 beamInfo->protonIntensity = beamInfo->tortgt;
00123
00124
00125
00126 SpillTimeFinder &stf = SpillTimeFinder::Instance();
00127 VldTimeStamp tons = stf.GetTimeOfNearestSpill(vldc);
00128 beamInfo->timeToNearestSpill = stf.GetTimeToNearestSpill(vldc);
00129 beamInfo->nearestSecToSpill = tons.GetSec();
00130 beamInfo->nearestNSToSpill = tons.GetNanoSec();
00131 VldTimeStamp ds = spillInfo.SpillTime()-vldc.GetTimeStamp();
00132 fSpillAna->SetTimeDiff(ds.GetSeconds());
00133 beamInfo->streamSpillTimeDiff = ds.GetSeconds();
00134 beamInfo->goodSpill = (int)fSpillAna->SelectSpill();
00135
00136
00137
00138 if(det == Detector::kFar){
00139 SpillServerMonFinder& spillFinder = SpillServerMonFinder::Instance();
00140 const SpillServerMon& nearestSpill= spillFinder.GetNearestSpill(vldc);
00141 tons = nearestSpill.GetSpillTime()-timeStamp;
00142 beamInfo->deltaSecToSpillGPS = TMath::Abs(tons.GetSec());
00143 beamInfo->gpsError = nearestSpill.GetSpillTimeError();
00144 }
00145 }
00146 else if(dataType == SimFlag::kMC){
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161 }
00162
00163 return;
00164 }
00165
00166
00167
00168 void ANtpInfoObjectFillerBeam::FillBeamInformation(NtpBDLiteRecord *record,
00169 ANtpBeamInfo *beamInfo)
00170 {
00171
00172 beamInfo->Reset();
00173
00174
00175 if(record){
00176
00177 double x = 0.;
00178 double y = 0.;
00179 double xrms = 0.;
00180 double yrms = 0.;
00181
00182
00183 BeamMonSpill spillInfo;
00184
00185
00186 fSpillAna->SetSpill(*record, spillInfo);
00187 spillInfo.BpmAtTarget(x,y,xrms,yrms);
00188
00189 beamInfo->tor101 = spillInfo.fTor101;
00190 beamInfo->tr101d = spillInfo.fTr101d;
00191 beamInfo->tortgt = spillInfo.fTortgt;
00192 beamInfo->trtgtd = spillInfo.fTrtgtd;
00193 beamInfo->hornCurrent = spillInfo.fHornCur;
00194 beamInfo->targetBPMX = x;
00195 beamInfo->targetBPMY = y;
00196 beamInfo->profileWidthX = spillInfo.fProfWidX;
00197 beamInfo->profileWidthY = spillInfo.fProfWidY;
00198 beamInfo->hadronIntensity = spillInfo.fHadInt;
00199 beamInfo->muonIntensity1 = spillInfo.fMuInt1;
00200 beamInfo->muonIntensity2 = spillInfo.fMuInt2;
00201 beamInfo->muonIntensity3 = spillInfo.fMuInt3;
00202 beamInfo->beamType = (Int_t)( spillInfo.BeamType() );
00203 beamInfo->protonIntensity = beamInfo->trtgtd;
00204
00205 beamInfo->timeToNearestSpill = record->dt_nearest;
00206 beamInfo->streamSpillTimeDiff = record->GetHeader().GetTimeDiffStreamSpill();
00207 beamInfo->nearestSecToSpill = record->nearest_sec;
00208 beamInfo->nearestNSToSpill = record->nearest_nsec;
00209 beamInfo->goodSpill = (int)fSpillAna->SelectSpill();
00210 }
00211
00212 return;
00213 }
00214
00215
00216
00217 void ANtpInfoObjectFillerBeam::FillBeamMCTruthInformation(NtpMCTruth *ntpMCTruth,
00218 TClonesArray *stdArray,
00219 ANtpTruthInfoBeam *truthInfo)
00220 {
00221
00222
00223 Int_t lowIndex = (Int_t)ntpMCTruth->stdhep[0];
00224 Int_t highIndex = (Int_t)ntpMCTruth->stdhep[1];
00225
00226 MSG("ANtpInfoObjectFillerBeam", Msg::kDebug) << "fill beam mc truth "
00227 << lowIndex << " " << highIndex
00228 << endl;
00229
00230
00231
00232 truthInfo->nuFlavor = ntpMCTruth->inu;
00233 truthInfo->nonOscNuEnergy = ntpMCTruth->p4neunoosc[3];
00234 truthInfo->nonOscNuDCosX = ntpMCTruth->p4neunoosc[0];
00235 truthInfo->nonOscNuDCosY = ntpMCTruth->p4neunoosc[1];
00236 truthInfo->nonOscNuDCosZ = ntpMCTruth->p4neunoosc[2];
00237 truthInfo->nonOscNuFlavor = ntpMCTruth->inunoosc;
00238 truthInfo->resonanceCode = ntpMCTruth->iresonance;
00239
00240 truthInfo->atomicWeight = ntpMCTruth->a;
00241 truthInfo->atomicNumber = ntpMCTruth->z;
00242 truthInfo->bjorkenX = ntpMCTruth->x;
00243 truthInfo->q2 = ntpMCTruth->q2;
00244 truthInfo->w2 = ntpMCTruth->w2;
00245 truthInfo->sigma = ntpMCTruth->sigma;
00246 truthInfo->emShowerFraction = ntpMCTruth->emfrac;
00247
00248 truthInfo->targetExitX = ntpMCTruth->flux.tvx;
00249 truthInfo->targetExitY = ntpMCTruth->flux.tvy;
00250 truthInfo->targetExitZ = ntpMCTruth->flux.tvz;
00251 truthInfo->targetParentPX = ntpMCTruth->flux.tpx;
00252 truthInfo->targetParentPY = ntpMCTruth->flux.tpy;
00253 truthInfo->targetParentPZ = ntpMCTruth->flux.tpz;
00254 truthInfo->targetParentType = ntpMCTruth->flux.tptype;
00255 truthInfo->parentX = ntpMCTruth->flux.vx;
00256 truthInfo->parentY = ntpMCTruth->flux.vy;
00257 truthInfo->parentZ = ntpMCTruth->flux.vz;
00258 truthInfo->parentPX = ntpMCTruth->flux.pdpx;
00259 truthInfo->parentPY = ntpMCTruth->flux.pdpy;
00260 truthInfo->parentPZ = ntpMCTruth->flux.pdpz;
00261 truthInfo->parentPID = ntpMCTruth->flux.ptype;
00262
00263 NtpMCStdHep *ntpMCStdHep = 0;
00264
00265
00266 Int_t nucleon = 0;
00267 Int_t nuFlavor = ntpMCTruth->inu;
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280 truthInfo->trueVisibleE = 0.;
00281
00282 int idHEP = 0;
00283 int istHEP = 0;
00284 bool gotOneAlreadyMate = false;
00285
00286 for(Int_t i = lowIndex; i < highIndex+1; ++i){
00287
00288 ntpMCStdHep = dynamic_cast<NtpMCStdHep *>(stdArray->At(i));
00289
00290 idHEP = ntpMCStdHep->IdHEP;
00291 istHEP = ntpMCStdHep->IstHEP;
00292
00293 if(TMath::Abs(idHEP) > 16
00294 && TMath::Abs(idHEP) < 1e5
00295 && istHEP == 1){
00296
00297 if(idHEP == 2212 || idHEP == 2112)
00298 truthInfo->trueVisibleE += ntpMCStdHep->p4[3] - ntpMCStdHep->mass;
00299 else
00300 truthInfo->trueVisibleE += ntpMCStdHep->p4[3];
00301 }
00302
00303 if(istHEP == 11){
00304 if(idHEP == 2212) nucleon = 1;
00305 else if(idHEP == 2112) nucleon = 0;
00306 else if(TMath::Abs(idHEP) > 1000000000) nucleon = 2;
00307 else nucleon = 3;
00308 }
00309
00310 if(nucleon == 1 && nuFlavor > 0) truthInfo->initialState = 1;
00311 else if(nucleon == 0 && nuFlavor > 0) truthInfo->initialState = 2;
00312 else if(nucleon == 1 && nuFlavor < 0) truthInfo->initialState = 3;
00313 else if(nucleon == 0 && nuFlavor < 0) truthInfo->initialState = 4;
00314 else if(nucleon == 2 && nuFlavor > 0) truthInfo->initialState = 5;
00315 else if(nucleon == 3 && nuFlavor > 0) truthInfo->initialState = 6;
00316 else if(nucleon == 2 && nuFlavor < 0) truthInfo->initialState = 7;
00317 else if(nucleon == 3 && nuFlavor < 0) truthInfo->initialState = 8;
00318
00319
00320 if(istHEP == 3 && !gotOneAlreadyMate){
00321 if(ntpMCTruth->iresonance != 1002 || TMath::Abs(idHEP) != 15){
00322 truthInfo->hadronicFinalState = idHEP%1000;
00323 gotOneAlreadyMate = true;
00324 }
00325 }
00326
00327 }
00328
00329 return;
00330 }