Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

TruthHelp.cxx

Go to the documentation of this file.
00001 #include <cassert>
00002 #include <vector>
00003 
00004 #include "TMath.h"
00005 
00006 #include "AtNuEvent/AtmosEvent.h"
00007 #include "AtNuEvent/AtmosMC.h"
00008 #include "AtNuEvent/AtmosScintHit.h"
00009 #include "AtNuEvent/AtmosStrip.h"
00010 #include "AtNuEvent/AtmosShower.h"
00011 #include "AtNuEvent/AtmosTrack.h"
00012 
00013 #include "MessageService/MsgService.h"
00014 
00015 #include "AtNuUtils/UtilMisc.h"
00016 #include "AtNuUtils/TruthHelp.h"
00017 
00018 class SimpleScintHit
00019 {
00020  public:
00021   SimpleScintHit() {TCInd = 0; Strip = 0;}
00022   SimpleScintHit(int i, int s) {TCInd = i; Strip = s;}
00023   int TCInd;
00024   int Strip;
00025 };
00026 
00027 class SimpleScintPlane
00028 {
00029  public:
00030   SimpleScintPlane() {Plane = 0; TotalDE = 0.0;}
00031   SimpleScintPlane(int pln) {Plane = pln; TotalDE = 0.0;}
00032   int Plane;
00033   double TotalDE;
00034 
00035   vector<SimpleScintHit> Hits;
00036 };
00037 
00038 CVSID("$Id: TruthHelp.cxx,v 1.4 2008/04/04 21:52:53 bspeak Exp $");
00039 
00040 TruthHelp::TruthHelp()
00041 {
00042   this->Zero();
00043 }
00044 
00045 TruthHelp::TruthHelp(const AtmosEvent* event)
00046 {
00047   this->Zero();
00048   this->Fill(event);
00049 }
00050 
00051 void TruthHelp::Zero() {
00052   TrkIdToId.clear();
00053   AssociateHits.clear();
00054 
00055   AllHits.clear();
00056   LeptonHits.clear();
00057   HadronHits.clear();
00058   NoiseHits.clear();
00059   DeMuxFailures.clear();
00060 }
00061 
00062 void TruthHelp::Fill(const AtmosEvent* event) {
00063   if(!event) return;
00064   this->Zero();
00065   MSG("FarDetEvent",Msg::kVerbose) << "TruthHelp::Fill" << endl;
00066 
00067   MakeTrkIdToId(event);
00068 
00069   MakeAssociateHits(event);
00070 
00071   ClassHits(event);
00072 }
00073 
00074 void TruthHelp::MakeTrkIdToId(const AtmosEvent *event) {
00075   if(!event) return;
00076   TrkIdToId.clear();
00077   
00078   for (int i=0; i<event->ScintHitList->GetEntries(); i++) {
00079     const AtmosScintHit* hit =
00080       dynamic_cast<const AtmosScintHit*>(event->ScintHitList->At(i));
00081     assert(hit);
00082     //The first hit in the TClonesArray decides if Lepton or not
00083     if (TrkIdToId.find(TMath::Abs(hit->TrkId)) == TrkIdToId.end()) {
00084       TrkIdToId[TMath::Abs(hit->TrkId)] = hit->Id;
00085     }
00086   }
00087 }
00088 
00089 void TruthHelp::MakeAssociateHits(const AtmosEvent *event) {
00090   if(!event) return;
00091   AssociateHits.clear();
00092   DeMuxFailures.clear();
00093 
00094   static SimpleScintPlane ScintPlanes[485];
00095   for(int i=0; i<485; i++) {
00096     ScintPlanes[i].Plane = i+1;
00097     ScintPlanes[i].TotalDE = 0.0;
00098     ScintPlanes[i].Hits.clear();
00099   }
00100 
00101   for (int i=0; i<event->ScintHitList->GetEntries(); i++) {
00102     const AtmosScintHit* hit =
00103       dynamic_cast<const AtmosScintHit*>(event->ScintHitList->At(i));
00104     assert(hit);
00105     ScintPlanes[hit->Plane-1].Hits.push_back(SimpleScintHit(i, hit->Strip));
00106     ScintPlanes[hit->Plane-1].TotalDE += hit->DE;
00107   }
00108 
00109   for (int istrip=0; istrip<event->StripList->GetEntries(); istrip++) {
00110     vector<int> Hit;
00111     const AtmosStrip *strip = 
00112       dynamic_cast<AtmosStrip*>(event->StripList->At(istrip));
00113     SimpleScintPlane &thisScintPlane = ScintPlanes[strip->Plane - 1];
00114 
00115     //Not enough DE in plane noise hit
00116     if (thisScintPlane.TotalDE < 1e-4) {
00117       MSG("FarDetEvent",Msg::kDebug) << "Strip " << strip->Strip << " in plane "
00118              << strip->Plane << " has too little plane DE" << endl;
00119       AssociateHits.push_back(Hit);
00120       continue;
00121     }
00122 
00123     //Check all ganged strips, starting with the bang on strip
00124     vector<int> Gang0 = UtilStrip::GangedStrips(strip->Strip,0);
00125     vector<int> Gang1 = UtilStrip::GangedStrips(strip->Strip,1);
00126 
00127     bool MatchActual = false;//True if the actual strip has a match
00128     for (unsigned int i=0; i<thisScintPlane.Hits.size(); i++) {
00129       SimpleScintHit &thisScintHit = thisScintPlane.Hits[i];
00130       vector<int>::iterator F0 = 
00131         std::find(Gang0.begin(),Gang0.end(),thisScintHit.Strip);
00132       vector<int>::iterator F1 = 
00133         std::find(Gang1.begin(),Gang1.end(),thisScintHit.Strip);
00134 
00135       bool MatchStrip = false;
00136       if(strip->Qadc[0]>0.0 && F0!=Gang0.end() ) MatchStrip = true;
00137       if(strip->Qadc[1]>0.0 && F1!=Gang1.end() ) MatchStrip = true;
00138       if(MatchStrip) Hit.push_back(thisScintHit.TCInd);
00139 
00140       if(strip->Qadc[0]>0.0 && F0==Gang0.begin() ) MatchActual = true;
00141       if(strip->Qadc[1]>0.0 && F1==Gang1.begin() ) MatchActual = true;
00142 
00143       vector<int>::iterator sps;
00144       if (strip->Qadc[0]>0.0 && F0!=Gang0.begin() && F0!=Gang0.end()) {
00145         MSG("FarDetEvent",Msg::kSynopsis) << "East DeMux Failure on Plane = " << strip->Plane
00146                << ", Strip = " << strip->Strip << endl;
00147         MSG("FarDetEvent",Msg::kSynopsis) << "Ganged Strips =";
00148         for(unsigned int i=0; i<Gang0.size(); i++) MSG("FarDetEvent",Msg::kSynopsis) << " " << Gang0[i];
00149         MSG("FarDetEvent",Msg::kSynopsis) << endl;
00150         MSG("FarDetEvent",Msg::kSynopsis) << "ScintHit Strip = " << thisScintHit.Strip << endl;
00151       }
00152 
00153       if (strip->Qadc[1]>0.0 && F1!=Gang1.begin() && F1!=Gang1.end()) {
00154         MSG("FarDetEvent",Msg::kSynopsis) << "West DeMux Failure on Plane = " << strip->Plane
00155                << ", Strip = " << strip->Strip << endl;
00156         MSG("FarDetEvent",Msg::kSynopsis) << "Ganged Strips =";
00157         for(unsigned int i=0; i<Gang1.size(); i++) MSG("FarDetEvent",Msg::kSynopsis) << " " << Gang1[i];
00158         MSG("FarDetEvent",Msg::kSynopsis) << endl;
00159         MSG("FarDetEvent",Msg::kSynopsis) << "ScintHit Strip = " << thisScintHit.Strip << endl;
00160       }
00161     }
00162     if(!MatchActual) DeMuxFailures.insert(SetStrip(istrip,strip));
00163     AssociateHits.push_back(Hit);
00164   }
00165 
00166   /*
00167   set<SetStrip>::iterator sitr;
00168   MSG("FarDetEvent",Msg::kSynopsis) << "DeMuxFailures:" << endl;
00169   for (sitr=DeMuxFailures.begin(); sitr!=DeMuxFailures.end(); sitr++) {
00170     MSG("FarDetEvent",Msg::kSynopsis) << "  TCIndex = " << sitr->TCIndex << endl;
00171   }
00172   */
00173 }
00174 
00175 void TruthHelp::ClassHits(const AtmosEvent *event) {
00176   if(!event) return;
00177   AllHits.clear();
00178   LeptonHits.clear();
00179   HadronHits.clear();
00180   NoiseHits.clear();
00181   
00182   for (unsigned int i=0; i<AssociateHits.size(); i++) {
00183     const AtmosStrip* strip =
00184       dynamic_cast<const AtmosStrip*>(event->StripList->At(i));
00185     assert(strip);
00186 
00187     AllHits.insert(SetStrip(i, strip));
00188 
00189     const double stripPE = (strip->QPE[0]+strip->QPE[1]);
00190 
00191     //noise hit
00192     if (AssociateHits[i].size() == 0) {
00193       NoiseHits.insert(SetStrip(i,stripPE,strip->Ndigits-1));
00194       continue;
00195     }
00196 
00197     bool IsLep = false;
00198     bool IsHad = false;
00199     
00200     for (unsigned int j=0; j<AssociateHits[i].size(); j++) {
00201       int ThisIndex = AssociateHits[i][j];
00202       const AtmosScintHit* hit =
00203         dynamic_cast<const AtmosScintHit*>
00204         (event->ScintHitList->At(ThisIndex));
00205       assert(hit);
00206       if(UtilMisc::IdIsLepton(TrkIdToId[TMath::Abs(hit->TrkId)]))
00207         IsLep = true;
00208       else IsHad = true;
00209     }
00210     if(IsLep) LeptonHits.insert(SetStrip(i,stripPE,strip->Ndigits-1));
00211     if(IsHad) HadronHits.insert(SetStrip(i,stripPE,strip->Ndigits-1));
00212   }
00213 }

Generated on Mon Feb 15 11:07:47 2010 for loon by  doxygen 1.3.9.1