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

CalHit.cxx

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 #include <sstream>
00007 #include "RawData/RawDigit.h"
00008 #include "RecoBase/CellHit.h"
00009 #include "CalHit/CalHit.h"
00010 #include "JobControl/Exception.h"
00011 #include "Header/Header.h"
00012 #include "Utilities/EDMUtils.h"
00013 
00014 using namespace calhit;
00015 
00016 MODULE_DECL(CalHit);
00017 
00018 CalHit::CalHit(const char* version) : 
00019   jobc::Module("CalHit"),
00020   fCal(0),
00021   fGeo(0),
00022   fRawDigitInputFolder("."),
00023   fCellHitOutputFolder("Hits"),
00024   fRecoHitOutputFolder("Rough"),
00025   fRunRoughReco(0)
00026 {
00027   this->SetCfgVersion(version);
00028 }
00029 
00030 //......................................................................
00031 CalHit::~CalHit() { }
00032 
00033 //......................................................................
00034 
00035 void CalHit::Update(const cfg::Config& c)
00036 {
00037   c("RawDigitInputFolder").Get(fRawDigitInputFolder);
00038   c("CellHitOutputFolder").Get(fCellHitOutputFolder);
00039   c("RecoHitOutputFolder").Get(fRecoHitOutputFolder);
00040   c("RunRoughReco")       .Get(fRunRoughReco);
00041 }
00042 
00043 //......................................................................
00044 
00045 jobc::Result CalHit::Reco(edm::EventHandle& evt)
00046 {
00047 
00048   // Load the RawDigit list
00049   std::vector<const rawdata::RawDigit*> digitlist(0);
00050   try {
00051     evt.Raw().Get(fRawDigitInputFolder.c_str(),digitlist);
00052   } 
00053   catch (edm::Exception e) {
00054     return jobc::kFailed;
00055   }
00056 
00057   // Get a Calibrator instance for this event
00058   if (!fCal) fCal = &util::EDMUtils::GetCalibrator(evt);
00059 
00060   // Get a Geometry instance for this event, if needed (RoughReco)
00061   if (fRunRoughReco&&!fGeo) fGeo = &util::EDMUtils::GetGeometry(evt);
00062 
00063   // Make a CellHit for every RawDigit and write it out
00064   UInt_t Ndigits = digitlist.size();
00065 
00066   if (Ndigits) {
00067 
00068     // Make the output folder
00069     if(evt.Cal().GetFolder(fCellHitOutputFolder.c_str()) == 0)
00070       evt.Cal().MakeFolder(fCellHitOutputFolder.c_str());
00071 
00072     // Make the hits and write them out
00073     for (UInt_t iD=0;iD<Ndigits;iD++) {
00074 
00075       CellHit curr_cellhit;
00076       fCal->MakeCellHit(digitlist[iD],&curr_cellhit);
00077 
00078       evt.Cal().Put(curr_cellhit,fCellHitOutputFolder.c_str());
00079 
00080     }
00081 
00082     // Should we make rough RecoHits based on neighboring planes' hits?
00083     if (fRunRoughReco) RoughReco(evt);
00084 
00085   }
00086 
00087 
00088   return jobc::kPassed;
00089 
00090 }
00091 
00092 
00093 //-------
00094 // RoughReco probably shouldn't be in CalHit.  But, it's more of an
00095 // example of how to use the RecoHit class.  I don't expect any
00096 // physics to necessarily get done with the output of RoughReco.
00097 //
00098 // This code is simply an adaptation of P. Shanahan's pre-Oct-2009
00099 // version of CalHit.cxx.
00100 
00101 void CalHit::RoughReco(edm::EventHandle& evt) {
00102 
00103   // Load the CellHit list (just made)
00104   std::vector<const recobase::CellHit*> cellhitlist(0);
00105   evt.Cal().Get(fCellHitOutputFolder.c_str(),cellhitlist);
00106 
00107   // Make the output folder
00108   if(evt.Reco().GetFolder(fRecoHitOutputFolder.c_str()) == 0)
00109     evt.Reco().MakeFolder(fRecoHitOutputFolder.c_str());
00110 
00111   // to handle mean positions
00112   std::map<unsigned int, std::pair<double, double> > planeMean;
00113   planeMean.clear();
00114 
00115   // Get Q-weighted mean positions in each plane
00116   UInt_t Ncellhits = cellhitlist.size();
00117 
00118   for (UInt_t iC=0;iC<Ncellhits;iC++) {
00119     const CellHit *cellhit = cellhitlist[iC];
00120     UInt_t plane = cellhit->Plane();
00121     UInt_t cell  = cellhit->Cell();
00122 
00123     Double_t xyz[3];
00124     fGeo->Plane(plane).Cell(cell).GetCenter(xyz);
00125     Double_t viewpos = 0;
00126     if      (cellhit->View()==geo::kX) viewpos = xyz[0];
00127     else if (cellhit->View()==geo::kY) viewpos = xyz[1];
00128 
00129     if (planeMean.find(plane)==planeMean.end()) {
00130       // init
00131       planeMean[plane].first  = 0;
00132       planeMean[plane].second = 0;
00133     }
00134     planeMean[plane].first  += cellhit->PECorr();
00135     planeMean[plane].second += cellhit->PECorr()*viewpos;
00136   }
00137   
00138   // Determine ortho pos for each CellHit, and make the corresponding RecoHit
00139   for (UInt_t iC=0;iC<Ncellhits;iC++) {
00140     const CellHit *cellhit = cellhitlist[iC];
00141     UInt_t plane = cellhit->Plane();
00142 
00143     // first, just accumulate existing plane numbers in other view,
00144     // within 3 planes of hit planes
00145     // use a fixed array so we can skip specific elements later if necessary
00146     unsigned int planes[6]={9999,9999,9999,9999,9999,9999};
00147 
00148     // attempt to walk back three planes.  
00149     unsigned int pl=fGeo->NextPlaneOtherView(plane,-1);
00150     if (pl!=geo::kPLANE_NOT_FOUND) {
00151       planes[0]=pl;
00152       pl=fGeo->NextPlaneInView(pl,-1);// have to protect against Plane
00153       // not found, since otherwise the second
00154       // try will give the end of the detector
00155       if (pl!=geo::kPLANE_NOT_FOUND) { 
00156         planes[1]=pl;
00157         pl=fGeo->NextPlaneInView(pl,-1);
00158         if (pl!=geo::kPLANE_NOT_FOUND)  planes[2]=pl;
00159       }
00160     }
00161 
00162     // and forward three planes
00163     pl=fGeo->NextPlaneOtherView(plane,1);
00164     if (pl!=geo::kPLANE_NOT_FOUND) {
00165       planes[3]=pl;
00166       pl=fGeo->NextPlaneInView(pl,1);// have to protect against Plane
00167       // not found, since otherwise the second
00168       // try will give plane 1 (I think)
00169       if (pl!=geo::kPLANE_NOT_FOUND) {
00170         planes[4]=pl;
00171         pl=fGeo->NextPlaneInView(pl,1);
00172         if (pl!=geo::kPLANE_NOT_FOUND)  planes[5]=pl;
00173       }
00174     }
00175 
00176     double sPh=0; // sum of pulseheight and (ph-weighted) position 
00177     double sTPos=0;
00178 
00179     for (unsigned int ip=0; ip<6; ip++) {
00180       // only uses the -3 and +3 planes if we don't already have signal
00181       // from +/-1 and 2.
00182       if (sPh>0 && (ip==2 || ip==5) ) continue;
00183       
00184       unsigned int planeno=planes[ip];
00185       if (planeMean.find(planeno)!=planeMean.end()) {//9999 won't be found...
00186         sPh+=planeMean[planeno].first;
00187         sTPos+=planeMean[planeno].second;
00188       } 
00189     }
00190 
00191     // use middle of cell if position not calculable
00192     Double_t w = 0;
00193     if (sPh>0) w = sTPos/sPh;
00194 
00195     // Okay, got the ortho position (w).  Make the RecoHit.
00196     RecoHit recohit;
00197     fCal->MakeRecoHit(cellhit,&recohit,w);
00198     evt.Reco().Put(recohit,fRecoHitOutputFolder.c_str());
00199 
00200   } // hit loop
00201   
00202 }

Generated on Mon Nov 23 04:45:24 2009 for NOvA Offline by  doxygen 1.3.9.1