00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include <iostream>
00014 #include <algorithm>
00015 #include "StandardNtuple/NtpStRecord.h"
00016 #include "CandNtupleSR/NtpSRRecord.h"
00017 #include "CandNtupleSR/NtpSREvent.h"
00018 #include "CandNtupleSR/NtpSRTrack.h"
00019 #include "CandNtupleSR/NtpSRStrip.h"
00020 #include "MessageService/MsgService.h"
00021 #include "NueAna/NueAnaTools/SntpHelpers.h"
00022 #include "NueAna/HitCalcAna.h"
00023 #include "AnalysisNtuples/ANtpDefaultValue.h"
00024 #include "VertexFinder/NtpVtxFinder/NtpVtxFinder.h"
00025
00026 CVSID("$Id: HitCalcAna.cxx,v 1.27 2008/11/19 18:22:51 rhatcher Exp $");
00027
00028 using std::cout;
00029 using std::endl;
00030
00031 ClassImp(HitCalcAna)
00032
00033
00034
00035
00036
00037 HitCalcAna::HitCalcAna(HitCalc &hc):
00038 fHitCalc(hc)
00039 {
00040
00041
00042 }
00043
00044 HitCalcAna::~HitCalcAna()
00045 {
00046
00047
00048 }
00049
00050 void HitCalcAna::Analyze(int evtn
00051 ,RecRecordImp<RecCandHeader> *srobj)
00052 {
00053
00054 if(srobj==0){
00055 return;
00056 }
00057 if(((dynamic_cast<NtpStRecord *>(srobj))==0)&&
00058 ((dynamic_cast<NtpSRRecord *>(srobj))==0)){
00059 return;
00060 }
00061
00062 MSG("HitCalcAna",Msg::kInfo)<<"In HitCalcAna::Analyze"<<endl;
00063 MSG("HitCalcAna",Msg::kInfo)<<"On Snarl "<<srobj->GetHeader().GetSnarl()
00064 <<" event "<<evtn<<endl;
00065
00066 NtpSREvent *event = SntpHelpers::GetEvent(evtn,srobj);
00067 if(!event){
00068 MSG("HitCalcAna",Msg::kError)<<"Couldn't get event "<<evtn
00069 <<" from Snarl "
00070 <<srobj->GetHeader().GetSnarl()<<endl;
00071 return;
00072 }
00073
00074 Int_t hitTotal;
00075
00076
00077 hitTotal=ComputeHits(srobj,event);
00078
00079 if (hitTotal > 3){
00080
00081 VarCalc();
00082
00083 }
00084
00085 }
00086
00087 void HitCalcAna::Get3DHit(DeqFloat_t &x
00088 , DeqFloat_t &y
00089 , DeqFloat_t &z
00090 , DeqFloat_t &e)
00091 {
00092
00093 if(fX.size()==0 || fY.size()==0 || fZ.size()==0 || fE.size()==0){
00094 MSG("HitCalcAna",Msg::kWarning)<< "3D Hits not calculated for event,"
00095 << "stopping any further"
00096 << " Hit related processing."
00097 << endl;
00098 return;
00099 }
00100
00101
00102 x=fX;
00103 y=fY;
00104 z=fZ;
00105 e=fE;
00106
00107 }
00108
00109
00110 Int_t HitCalcAna::ComputeHits(RecRecordImp<RecCandHeader> *srobj
00111 ,NtpSREvent *event)
00112 {
00113
00114 if(srobj==0){
00115 return 1;
00116 }
00117 if(((dynamic_cast<NtpStRecord *>(srobj))==0)&&
00118 ((dynamic_cast<NtpSRRecord *>(srobj))==0)){
00119 return 1;
00120 }
00121
00122
00123 fX.clear();
00124 fY.clear();
00125 fZ.clear();
00126 fE.clear();
00127
00128
00129 Detector::Detector_t fDetectorType =
00130 srobj->GetHeader().GetVldContext().GetDetector();
00131
00132
00133
00134
00135 Float_t totalVisEnerg;
00136
00137
00138 Float_t hitX;
00139 Float_t hitY;
00140 Float_t hitZ;
00141 Float_t hitE;
00142
00143
00144 DeqFloat_t stripUV;
00145 DeqFloat_t stripZ;
00146 DeqFloat_t stripE;
00147
00148 DeqFloat_t stripUVTemp;
00149 DeqFloat_t stripZTemp;
00150 DeqFloat_t stripETemp;
00151
00152 Int_t nPlaneSM = 0;
00153
00154
00155 Int_t nMax = 0;
00156 Int_t nHit = 0;
00157
00158 Float_t vertexX = event->vtx.x;
00159 Float_t vertexY = event->vtx.y;
00160 Float_t vertexZ = event->vtx.z;
00161
00162 if(ReleaseType::IsCedar(release)){
00163 NtpSRTrack *primaryTrack = 0;
00164 NtpSRTrack *ntpTrack = 0;
00165 Int_t index = 0;
00166
00167 for(Int_t i = 0; i < event->ntrack; ++i){
00168 index = event->trk[i];
00169 ntpTrack = SntpHelpers::GetTrack(index, srobj);
00170 if(!primaryTrack) primaryTrack = ntpTrack;
00171
00172 if(ntpTrack->plane.n > primaryTrack->plane.n)
00173 primaryTrack = ntpTrack;
00174 }
00175
00176 NtpStRecord* st = dynamic_cast<NtpStRecord *>(srobj);
00177 NtpVtxFinder vtxf;
00178 vtxf.SetTargetEvent(st, event, primaryTrack);
00179 if(vtxf.FindVertex() > 0){
00180 vertexX = vtxf.VtxX();
00181 vertexY = vtxf.VtxY();
00182 vertexZ = vtxf.VtxZ();
00183 }
00184 }
00185
00186 Int_t event_end = event -> plane.end;
00187 Int_t event_start = event -> plane.beg;
00188
00189 if(fDetectorType == Detector::kNear){
00190 if (event_end >= 121) {
00191 MSG("HitCalcAna",Msg::kInfo)<< "ND event ends outside"
00192 << " calorimeter region in plane "
00193 << event_end
00194 <<". Truncated hit matching."
00195 << endl;
00196 event_end = 121;
00197 }
00198 if (event_start >= 121) {
00199 MSG("HitCalcAna",Msg::kError)<< "ND event starts outside"
00200 << " calorimeter region in "
00201 << event_start <<" Stopping."
00202 << endl;
00203 return 1;
00204 }
00205 }
00206
00207 totalVisEnerg = 0.0;
00208 nHit=0;
00209
00210 Float_t stpEDiff = 0.0;
00211
00212
00213 for(Int_t nPlane = event_start;
00214 nPlane < event_end; nPlane++){
00215
00216
00217 stripUVTemp.clear();
00218 stripZTemp.clear();
00219 stripETemp.clear();
00220
00221 stripUV.clear();
00222 stripZ.clear();
00223 stripE.clear();
00224
00225
00226 for(Int_t iStp = 0; iStp < event->nstrip; iStp++){
00227 Int_t index = SntpHelpers::GetStripIndex(iStp,event);
00228 NtpSRStrip *strip = SntpHelpers::GetStrip(index,srobj);
00229
00230 if(!strip){
00231 MSG("HitCalcAna",Msg::kDebug)<< "Couldn't get strip "<< index
00232 << " in snarl "
00233 << srobj->GetHeader().GetSnarl()
00234 << " next"<<endl;
00235 continue;
00236 }
00237 if(!evtstp0mip){
00238 MSG("HitCalcAna",Msg::kError)<<"No mip strip information"<<endl;
00239 continue;
00240 }
00241
00242
00243 float charge = evtstp0mip[index] + evtstp1mip[index];;
00244
00245 totalVisEnerg += charge;
00246
00247
00248 if(TMath::Abs(strip->z-vertexZ) < 4. && (charge)>200.0/sigcormeu){
00249
00250 if(strip->plane == nPlane){
00251 stripUVTemp.push_back(strip->tpos);
00252 stripZTemp.push_back(strip ->z);
00253 stripETemp.push_back(charge);
00254 }
00255
00256 if(strip->plane == (nPlane+1)){
00257 stripUV.push_back(strip->tpos);
00258 stripZ.push_back(strip ->z);
00259 stripE.push_back(charge);
00260 }
00261 }
00262 }
00263
00264
00265
00266
00267 for(UInt_t nStrip = 0; nStrip < stripZ.size(); nStrip++) {
00268 for(UInt_t nStripTemp = 0; nStripTemp < stripZTemp.size()
00269 ; nStripTemp++){
00270
00271 MSG("HitCalcAna",Msg::kDebug)<< "StripUV(" << nStrip
00272 << ") = "
00273 << stripUV.at(nStrip) << " "
00274 << "StripUVTemp(" << nStripTemp
00275 << ") = "
00276 << stripUVTemp.at(nStripTemp)
00277 << endl;
00278 MSG("HitCalcAna",Msg::kDebug)<< "StripZ(" << nStrip
00279 << ") = "
00280 << stripZ.at(nStrip) << " "
00281 << "StripZTemp(" << nStripTemp
00282 << ") = "
00283 << stripZTemp.at(nStripTemp)
00284 << endl;
00285
00286 MSG("HitCalcAna",Msg::kDebug)<< "StripE(" << nStrip
00287 << ") = "
00288 << stripE.at(nStrip) << " "
00289 << "StripETemp(" << nStripTemp
00290 << ") = "
00291 << stripETemp.at(nStripTemp)
00292 << endl;
00293
00294
00295
00296 if(stripUV.at(nStrip) != stripUVTemp.at(nStripTemp)
00297 && (stripUV.at(nStrip) > -99.
00298 && stripUVTemp.at(nStripTemp) > -99.)){
00299
00300 if(fDetectorType == Detector::kFar){
00301 stpEDiff=10;
00302
00303 if(nPlane >= 0 && nPlane <= 249)
00304 nPlaneSM = nPlane+1;
00305 if(nPlane >= 250 && nPlane <= 485)
00306 nPlaneSM = nPlane;
00307 }
00308
00309 if(fDetectorType == Detector::kNear||
00310 fDetectorType==Detector::kCalDet){
00311 nPlaneSM = nPlane;
00312 stpEDiff=10;
00313 }
00314
00315
00316
00317
00318
00319
00320 if(TMath::Abs(stripE.at(nStrip)
00321 -stripETemp.at(nStripTemp)) < stpEDiff ){
00322
00323 MSG("HitCalcAna",Msg::kDebug)<< "Found Hit "
00324 << nHit << endl;
00325
00326 hitX = pow((-1.0),nPlaneSM)*(sqrt(2.0)/2.0)
00327 *(stripUV.at(nStrip)-stripUVTemp.at(nStripTemp));
00328 hitY = (sqrt(2.0)/2.0)
00329 *(stripUV.at(nStrip)+stripUVTemp.at(nStripTemp));
00330 hitZ = (stripZ.at(nStrip)
00331 +stripZTemp.at(nStripTemp))/2.0;
00332 hitE = (stripE.at(nStrip)
00333 +stripETemp.at(nStripTemp))/2.0;
00334
00335 fX.push_back(hitX-vertexX);
00336 fY.push_back(hitY-vertexY);
00337 fZ.push_back(hitZ-vertexZ);
00338 fE.push_back(hitE);
00339
00340 MSG("HitCalcAna",Msg::kDebug)<< "Vertex Pos(X,Y,Z)= ("
00341 << vertexX << ","
00342 << vertexY << ","
00343 << vertexZ << ")"
00344 << endl << endl;
00345
00346 MSG("HitCalcAna",Msg::kDebug)<< "fX["
00347 << nHit <<"]= "
00348 << fX[nHit]
00349 << endl << endl;
00350
00351 MSG("HitCalcAna",Msg::kDebug)<< "fY["
00352 << nHit <<"]= "
00353 << fY[nHit]
00354 << endl << endl;
00355
00356 MSG("HitCalcAna",Msg::kDebug)<< "fZ["
00357 << nHit <<"]= "
00358 << fZ[nHit]
00359 << endl << endl;
00360
00361 MSG("HitCalcAna",Msg::kDebug)<< "fE["
00362 << nHit <<"]= "
00363 << fE[nHit]
00364 << endl << endl;
00365
00366 nHit++;
00367
00368 } else continue;
00369 }
00370 }
00371 }
00372 }
00373
00374 nMax = nHit;
00375
00376 MSG("HitCalcAna",Msg::kInfo)<< "Found "
00377 << nMax
00378 << " 3D Hits."
00379 << endl;
00380
00381 return nMax;
00382 }
00383
00384
00385 void HitCalcAna::Reset()
00386 {
00387
00388
00389 }
00390
00391 void HitCalcAna::VarCalc()
00392 {
00393
00394
00395
00396 Float_t totalHitEnerg;
00397 Float_t arg;
00398 Float_t argTheta;
00399 Float_t eTrans;
00400 Float_t eTransX;
00401 Float_t eTransY;
00402 Float_t sumETransX;
00403 Float_t sumETransY;
00404 Float_t eLong;
00405 Float_t sTrans;
00406
00407 Float_t phi;
00408 Float_t phiMax;
00409 Float_t phiEMax;
00410 Float_t thetaLMax;
00411 Float_t thetaEMax;
00412 Float_t s;
00413 Float_t sE;
00414
00415 Float_t length;
00416 Float_t lengthMax;
00417 Float_t eMax;
00418
00419 Float_t sumOppSide;
00420 Float_t sumSameSide;
00421 Float_t ratioFar;
00422
00423 Float_t sumOppSideE;
00424 Float_t sumSameSideE;
00425 Float_t ratioEnerg;
00426
00427 Int_t nFar;
00428 Int_t nEMax;
00429
00430 Float_t zMax;
00431 Float_t zL;
00432
00433 VecFloat_t theta;
00434 theta.assign(fZ.size(),0.0);
00435
00437
00438 sumETransX=0.0;
00439 sumETransY=0.0;
00440 eLong=0.0;
00441 sTrans=0.0;
00442 length=0.0;
00443 lengthMax=0.0;
00444 eMax=0.0;
00445 phiMax=0.0;
00446 phiEMax=0.0;
00447 thetaLMax=0.0;
00448 thetaEMax=0.0;
00449 nFar=0;
00450 nEMax=0;
00451 zMax=0;
00452 totalHitEnerg=0.0;
00453
00454 Float_t epsilon=0.00001;
00455
00456
00457 for (UInt_t n = 0; n < fZ.size(); n++){
00458 if(fZ.at(n) >= 0.0){
00459 totalHitEnerg += fE.at(n);
00460 if(fZ.at(n) > zMax) zMax = fZ.at(n);
00461 }
00462 }
00463
00464
00465 for (UInt_t n = 0; n < fZ.size(); n++){
00466 if(fZ.at(n) >= 0.0){
00467 if(fZ.at(n) == 0){ fZ.at(n) += epsilon; }
00468
00469 arg = fX.at(n)*fX.at(n)+fY.at(n)*fY.at(n);
00470 argTheta = TMath::Sqrt(arg)/fZ.at(n);
00471 theta.at(n) = TMath::ATan(argTheta);
00472 phi = TMath::ACos(fX.at(n)/(argTheta*fZ.at(n) + epsilon));
00473
00474 MSG("HitCalcAna",Msg::kDebug)<< "Intermediate VarCalc Monitor "
00475 << endl
00476 << "arg = " << arg << endl
00477 << "argTheta = " << argTheta
00478 << endl
00479 << "fE[" << n << "] = " << fE.at(n)
00480 << endl
00481 << "fX = " << fX.at(n) << endl
00482 << "fY = " << fY.at(n) << endl
00483 << "fZ = " << fZ.at(n) << endl
00484 << "theta = " << theta.at(n)
00485 << endl << endl;
00486
00487 eTransX = fE.at(n)*fX.at(n)*TMath::Cos(theta.at(n))/fZ.at(n);
00488 eTransY = fE.at(n)*fY.at(n)*TMath::Cos(theta.at(n))/fZ.at(n);
00489 sumETransX += eTransX;
00490 sumETransY += eTransY;
00491
00492 sTrans += (eTransX*eTransX+eTransY*eTransY);
00493
00494
00495 eLong += fE.at(n)*TMath::Cos(theta.at(n));
00496
00497
00498 MSG("HitCalcAna",Msg::kDebug)<< "Intermediate VarCalc Monitor "
00499 << endl
00500 << "sumETransX[" << n << "] = "
00501 << sumETransX << endl
00502 << "sumETransY[" << n << "] = "
00503 << sumETransY << endl
00504 << "eLong = " << eLong
00505 << endl << endl;
00506
00507
00508 length = TMath::Sqrt(arg+fZ.at(n)*fZ.at(n));
00509 if(length > lengthMax){
00510 if ( fZ.at(n) > 0.8*zMax
00511 && fZ.at(n) <= zMax){
00512
00513
00514
00515 lengthMax = length;
00516 nFar = n;
00517 zL = fZ.at(n);
00518 phiMax = phi;
00519 thetaLMax = theta.at(n);
00520 }
00521 }
00522
00523
00524 if(fE.at(n) > eMax){
00525 eMax = fE.at(n);
00526 nEMax = n;
00527 phiEMax = phi;
00528 thetaEMax = theta.at(n);
00529 }
00530 }
00531 }
00532
00533 eTrans = TMath::Sqrt(sumETransX*sumETransX
00534 +sumETransY*sumETransY);
00535
00536
00537 sumSameSide = 0.0;
00538 sumOppSide = 0.0;
00539 sumSameSideE = 0.0;
00540 sumOppSideE = 0.0;
00541
00542 for (UInt_t n=0; n < fZ.size(); n++){
00543 if(fZ.at(n) >= 0.0){
00544
00545 s = fX.at(n)*TMath::Cos(phiMax)+fY.at(n)*TMath::Sin(phiMax);
00546
00547 if(s >= 0.0) sumSameSide += fE.at(n)*TMath::Sin(theta.at(n));
00548 else sumOppSide += fE.at(n)*TMath::Sin(theta.at(n));
00549
00550
00551 sE = fX.at(n)*TMath::Cos(phiEMax)+fY.at(n)*TMath::Sin(phiEMax);
00552
00553 if(sE >= 0.0) sumSameSideE += fE.at(n)*TMath::Sin(theta.at(n));
00554 else sumOppSideE += fE.at(n)*TMath::Sin(theta.at(n));
00555
00556 }
00557 }
00558
00559 if (sumSameSide > 0.0){
00560 ratioFar = sumOppSide/sumSameSide;
00561 }else ratioFar = ANtpDefVal::kFloat;
00562
00563 if (sumSameSideE > 0.0){
00564 ratioEnerg = sumOppSideE/sumSameSideE;
00565 }else ratioEnerg = ANtpDefVal::kFloat;
00566
00567 if (ratioFar > 50.0) {ratioFar = ANtpDefVal::kFloat;}
00568 if (ratioEnerg > 50.0) {ratioEnerg = ANtpDefVal::kFloat;}
00569
00570 MSG("HitCalcAna",Msg::kInfo)<< "Calculated Hit variables " << endl
00571 << "eTotal = " << totalHitEnerg
00572 << " eTrans = " << eTrans
00573 << " eLong = " << eLong
00574 << " sTrans = " << sTrans
00575 << " farMomBalance = " << ratioFar
00576 << " peakMomBalance = " << ratioEnerg
00577 << " farAngle = " << thetaLMax
00578 << " peakAngle = " << thetaEMax
00579 << " zMax = " << zMax << endl;
00580
00581 Float_t transLongRatio=ANtpDefVal::kFloat;
00582 if(eLong > 0.0){transLongRatio=eTrans/eLong;}
00583
00584
00585 if (totalHitEnerg > 0.0){
00586 fHitCalc.fHitTotalEnergy = totalHitEnerg;
00587 fHitCalc.fHitTransEnergy = eTrans;
00588 fHitCalc.fHitLongEnergy = eLong;
00589 fHitCalc.fHitTransCMEnergy = sTrans;
00590 fHitCalc.fHitTransEnergyRatio = eTrans/totalHitEnerg;
00591 fHitCalc.fHitLongEnergyRatio = eLong/totalHitEnerg;
00592 fHitCalc.fHitTransLongEnergyRatio = transLongRatio;
00593 fHitCalc.fHitTransCMEnergyRatio = sTrans/totalHitEnerg;
00594 fHitCalc.fHitFarMomBalance = ratioFar;
00595 fHitCalc.fHitPeakMomBalance = ratioEnerg;
00596 fHitCalc.fHitFarAngle = thetaLMax;
00597 fHitCalc.fHitPeakAngle = thetaEMax;
00598 }
00599 else {
00600 MSG("HitCalcAna",Msg::kInfo)<< "No hits found in Event" << endl;
00601 fHitCalc.fHitTotalEnergy = ANtpDefVal::kFloat;
00602 fHitCalc.fHitTransEnergy = ANtpDefVal::kFloat;
00603 fHitCalc.fHitLongEnergy = ANtpDefVal::kFloat;
00604 fHitCalc.fHitTransCMEnergy = ANtpDefVal::kFloat;
00605 fHitCalc.fHitTransEnergyRatio = ANtpDefVal::kFloat;
00606 fHitCalc.fHitLongEnergyRatio = ANtpDefVal::kFloat;
00607 fHitCalc.fHitTransLongEnergyRatio = ANtpDefVal::kFloat;
00608 fHitCalc.fHitTransCMEnergyRatio = ANtpDefVal::kFloat;
00609 fHitCalc.fHitFarMomBalance = ANtpDefVal::kFloat;
00610 fHitCalc.fHitPeakMomBalance = ANtpDefVal::kFloat;
00611 fHitCalc.fHitFarAngle = ANtpDefVal::kFloat;
00612 fHitCalc.fHitPeakAngle = ANtpDefVal::kFloat;
00613
00614 }
00615 }