00001
00002
00003
00004
00005
00007
00008 #include <cassert>
00009
00010 #include "CandChop/AlgChopListSharp.h"
00011 #include "CandChop/CandChopListHandle.h"
00012 #include "CandChop/DigitVector.h"
00013
00014
00015 #include "Algorithm/AlgConfig.h"
00016 #include "Algorithm/AlgFactory.h"
00017 #include "Algorithm/AlgHandle.h"
00018 #include "CandData/CandHeader.h"
00019 #include "CandData/CandRecord.h"
00020 #include "CandDigit/CandDigitHandle.h"
00021 #include "CandDigit/CandDigitListHandle.h"
00022 #include "CandDigit/CandDigitList.h"
00023 #include "Candidate/CandContext.h"
00024 #include "MessageService/MsgService.h"
00025 #include "MinosObjectMap/MomNavigator.h"
00026 #include "RawData/RawHeader.h"
00027 #include "RawData/RawRecord.h"
00028 #include "RawData/RawDigitDataBlock.h"
00029 #include "UgliGeometry/UgliGeomHandle.h"
00030 #include "UgliGeometry/UgliStripHandle.h"
00031 #include "Validity/VldContext.h"
00032 #include "Calibrator/Calibrator.h"
00033
00034 ClassImp(AlgChopListSharp)
00035 CVSID( " $Id: AlgChopListSharp.cxx,v 1.2 2005/05/19 17:55:33 tagg Exp $ ");
00036
00037 struct compareDigitTimes : public binary_function<const CandDigitHandle&, const CandDigitHandle&, bool> {
00038 bool operator()(const CandDigitHandle& d1, const CandDigitHandle& d2) {
00039 return (d1.GetTime() < d2.GetTime());
00040 }
00041 };
00042
00043 const RawChannelId kQieRcid(DetectorType::kNear,ElecType::kQIE,0,0,false,false);
00044 const float k1pe = 100.;
00045
00046
00047
00048 AlgChopListSharp::AlgChopListSharp()
00049 {
00050 }
00051
00052
00053 AlgChopListSharp::~AlgChopListSharp()
00054 {
00055 }
00056
00057
00058 bool AlgChopListSharp::ShouldSplit( float this_ph,
00059 float next_ph,
00060 float
00061 )
00062 {
00063 float climb = next_ph - this_ph;
00064
00065
00066 float max_climb = 2.5*sqrt(fabs(this_ph)/k1pe)*k1pe;
00067 if(max_climb < (6 * k1pe)) max_climb=max_climb*2;
00068
00069
00070
00071
00072
00073
00074
00075
00076 if( climb >= max_climb ) return true;
00077 else return false;
00078 }
00079
00080
00081
00082 void AlgChopListSharp::RunAlg(AlgConfig& ,
00083 CandHandle &candHandle,
00084 CandContext &candContext)
00085 {
00089
00090 assert(candHandle.InheritsFrom("CandChopListHandle"));
00091 CandChopListHandle &chopList = dynamic_cast<CandChopListHandle &>(candHandle);
00092
00093 assert(candContext.GetDataIn());
00094
00095 if (!(candContext.GetDataIn()->InheritsFrom("CandDigitListHandle"))) {
00096 MSG("Chop",Msg::kWarning ) << "Data into AlgChopListSharp is not a digit list." << std::endl;
00097 }
00098
00099 const CandDigitListHandle *cdlh_ptr =
00100 dynamic_cast<const CandDigitListHandle*>(candContext.GetDataIn());
00101
00102 const MomNavigator *mom = candContext.GetMom();
00103 RawRecord *rr = dynamic_cast<RawRecord *>(mom->GetFragment("RawRecord"));
00104 if (!rr) {
00105 MSG("Chop", Msg::kWarning) << "No RawRecord in MOM." << endl;
00106 return;
00107 }
00108 const RawDigitDataBlock *rddb = dynamic_cast<const RawDigitDataBlock *>
00109 (rr->FindRawBlock("RawDigitDataBlock"));
00110 if (!rddb) {
00111 MSG("Chop", Msg::kWarning) << "No RawDigitDataBlock in RawRecord." << endl;
00112 return;
00113 }
00114
00115
00116 AlgFactory &af = AlgFactory::GetInstance();
00117 AlgHandle ah = af.GetAlgHandle("AlgChop","default");
00118 CandContext cxx(this,candContext.GetMom());
00119
00120 const VldContext &context = *(candContext.GetCandRecord()->GetVldContext());
00121 if(context.GetDetector() != DetectorType::kNear)
00122 MSG("Chop",Msg::kError) << "Running the Sharp algorithm on FD data is a no-no!" << endl;
00123
00124 Calibrator& cal = Calibrator::Instance();
00125 UgliGeomHandle ugli(context);
00126
00127
00128
00129
00130 DigitVector digits(cdlh_ptr);
00131
00132 UInt_t ndigits = digits.size();
00133 UInt_t nchop = 0;
00134
00135
00136
00137
00138
00139
00140
00141 std::vector<int> digit_tdc(ndigits);
00142 std::vector<UInt_t> digit_plane(ndigits);
00143
00144 for(UInt_t i=0;i<ndigits;i++) {
00145 digit_tdc[i] = (cal.GetTDCFromTime(digits[i].GetTime(CalTimeType::kNone), kQieRcid));
00146 digit_plane[i] = digits[i].GetPlexSEIdAltL().GetPlane();
00147
00148
00149
00150
00151 }
00152
00153
00154 Int_t tfirst = digit_tdc[0];
00155 Int_t tlast = digit_tdc[0];
00156 for(UInt_t i=0;i<ndigits;i++) {
00157 if(digit_tdc[i] < tfirst) tfirst = digit_tdc[i];
00158 if(digit_tdc[i] > tlast ) tlast = digit_tdc[i];
00159 }
00160 tfirst-=5;
00161 tlast +=5;
00162
00163
00164
00165 MSG("Chop",Msg::kDebug) << "Running Chop_Sharp" << endl;
00166
00167 UInt_t numBins = tlast-tfirst;
00168
00169
00170 std::vector<float> energyVsTime(numBins,0.);
00171
00172 for(UInt_t idig = 0; idig < ndigits; idig++ ) {
00173 float sigcor = digits[idig].GetCharge(CalDigitType::kSigCorr);
00174 int tdcbin = digit_tdc[idig]-tfirst;
00175 if((tdcbin<0) || ((int)numBins<=tdcbin)) MSG("Chop",Msg::kDebug) << "Whups!" << endl;
00176 else if(digit_plane[idig]<=PlexPlaneId::LastPlaneNearCalor()) {
00177 energyVsTime[digit_tdc[idig]-tfirst] += sigcor;
00178 }
00179 }
00180
00181
00182 std::vector<char> binsUsed(numBins,0);
00183
00184 do {
00185
00186 UInt_t biggest_bin = 99999;
00187 float biggest_size = 0;
00188 for(UInt_t i=0;i<numBins;i++) {
00189 if(binsUsed[i]==0)
00190 if(energyVsTime[i]>biggest_size) {
00191 biggest_size = energyVsTime[i];
00192 biggest_bin = i;
00193 }
00194 }
00195
00196 if(biggest_bin==99999) break;
00197 if(biggest_size<100.) break;
00198
00199
00200
00201 UInt_t bin_start = biggest_bin;
00202 UInt_t bin_stop = biggest_bin;
00203
00204
00205
00206
00207
00208 if(binsUsed[bin_start-1]==0) bin_start--;
00209 if(binsUsed[bin_stop +1]==0) bin_stop++;
00210
00211 bool done = false;
00212 while(!done) {
00213
00214 if(bin_start==0) {
00215
00216 done=true;
00217 }
00218
00219 if(ShouldSplit(energyVsTime[bin_start],
00220 energyVsTime[bin_start-1],
00221 bin_start-1 - biggest_bin ) ) {
00222
00223 done = true;
00224 }
00225
00226
00227 if(binsUsed[bin_start-1]) {
00228
00229 done = true;
00230 }
00231
00232 if(!done) {
00233
00234 bin_start--;
00235 }
00236 };
00237
00238
00239
00240 done = false;
00241 while(!done) {
00242
00243 if(bin_stop >= numBins-1) {
00244
00245 done = true;
00246 }
00247
00248
00249 if((energyVsTime[bin_stop+1] < 500.) && (bin_stop+1 < biggest_bin+7)) {
00250
00251 } else {
00252 if(ShouldSplit(energyVsTime[bin_stop],
00253 energyVsTime[bin_stop+1],
00254 bin_stop+1 - biggest_bin) ) {
00255
00256 done = true;
00257 }
00258 }
00259
00260
00261 if(binsUsed[bin_stop+1]) {
00262
00263 done = true;
00264 }
00265
00266
00267 if(!done) bin_stop++;
00268 }
00269
00270 int tdc_start = bin_start+tfirst;
00271 int tdc_stop = bin_stop+tfirst;
00272
00273
00274 DigitVector slc;
00275
00276 for(UInt_t idig = 0; idig < ndigits; idig++ ) {
00277 int tdc = digit_tdc[idig];
00278 if((tdc>=(int)tdc_start)&&(tdc<=(int)tdc_stop))
00279 slc.push_back(digits[idig]);
00280 }
00281 cxx.SetDataIn(&(slc));
00282 CandDigitListHandle chopHandle = CandDigitList::MakeCandidate(ah,cxx);
00283 chopHandle.SetName(Form("Chop %d",nchop++));
00284 chopList.AddDaughterLink(chopHandle);
00285
00286 MSG("Chop",Msg::kDebug) << "Creating chop. Big: " << biggest_bin
00287 << " Start: " << bin_start << " Stop: " << bin_stop
00288 << " Digits: " << slc.size()
00289 << endl;
00290
00291
00292
00293
00294 for(UInt_t i=bin_start; i<=bin_stop; i++) {
00295 binsUsed[i] = 1;
00296 }
00297
00298 } while(true);
00299
00300 }
00301
00302
00303 void AlgChopListSharp::Trace(const char * ) const
00304 {
00305 }
00306