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
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
00058 if (!fCal) fCal = &util::EDMUtils::GetCalibrator(evt);
00059
00060
00061 if (fRunRoughReco&&!fGeo) fGeo = &util::EDMUtils::GetGeometry(evt);
00062
00063
00064 UInt_t Ndigits = digitlist.size();
00065
00066 if (Ndigits) {
00067
00068
00069 if(evt.Cal().GetFolder(fCellHitOutputFolder.c_str()) == 0)
00070 evt.Cal().MakeFolder(fCellHitOutputFolder.c_str());
00071
00072
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
00083 if (fRunRoughReco) RoughReco(evt);
00084
00085 }
00086
00087
00088 return jobc::kPassed;
00089
00090 }
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 void CalHit::RoughReco(edm::EventHandle& evt) {
00102
00103
00104 std::vector<const recobase::CellHit*> cellhitlist(0);
00105 evt.Cal().Get(fCellHitOutputFolder.c_str(),cellhitlist);
00106
00107
00108 if(evt.Reco().GetFolder(fRecoHitOutputFolder.c_str()) == 0)
00109 evt.Reco().MakeFolder(fRecoHitOutputFolder.c_str());
00110
00111
00112 std::map<unsigned int, std::pair<double, double> > planeMean;
00113 planeMean.clear();
00114
00115
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
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
00139 for (UInt_t iC=0;iC<Ncellhits;iC++) {
00140 const CellHit *cellhit = cellhitlist[iC];
00141 UInt_t plane = cellhit->Plane();
00142
00143
00144
00145
00146 unsigned int planes[6]={9999,9999,9999,9999,9999,9999};
00147
00148
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);
00153
00154
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
00163 pl=fGeo->NextPlaneOtherView(plane,1);
00164 if (pl!=geo::kPLANE_NOT_FOUND) {
00165 planes[3]=pl;
00166 pl=fGeo->NextPlaneInView(pl,1);
00167
00168
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;
00177 double sTPos=0;
00178
00179 for (unsigned int ip=0; ip<6; ip++) {
00180
00181
00182 if (sPh>0 && (ip==2 || ip==5) ) continue;
00183
00184 unsigned int planeno=planes[ip];
00185 if (planeMean.find(planeno)!=planeMean.end()) {
00186 sPh+=planeMean[planeno].first;
00187 sTPos+=planeMean[planeno].second;
00188 }
00189 }
00190
00191
00192 Double_t w = 0;
00193 if (sPh>0) w = sTPos/sPh;
00194
00195
00196 RecoHit recohit;
00197 fCal->MakeRecoHit(cellhit,&recohit,w);
00198 evt.Reco().Put(recohit,fRecoHitOutputFolder.c_str());
00199
00200 }
00201
00202 }