89 APV->isMasked = SiStripQuality_->
IsApvBad(APV->DetId,APV->APVId);
92 float newPreviousGain = gainHandle->
getApvGain(APV->APVId,gainHandle->
getRange(APV->DetId, 1),1);
93 if(APV->PreviousGain!=1 and newPreviousGain!=APV->PreviousGain)
edm::LogWarning(
"SiStripGainPCLHarvester")<<
"WARNING: ParticleGain in the global tag changed\n";
94 APV->PreviousGain = newPreviousGain;
96 float newPreviousGainTick = gainHandle->
getApvGain(APV->APVId,gainHandle->
getRange(APV->DetId, 0),0);
97 if(APV->PreviousGainTick!=1 and newPreviousGainTick!=APV->PreviousGainTick){
98 edm::LogWarning(
"SiStripGainPCLHarvester")<<
"WARNING: TickMarkGain in the global tag changed\n"<< std::endl
99 <<
" APV->SubDet: "<< APV->SubDet <<
" APV->APVId:" << APV->APVId << std::endl
100 <<
" APV->PreviousGainTick: "<<APV->PreviousGainTick<<
" newPreviousGainTick: "<<newPreviousGainTick<<std::endl;
102 APV->PreviousGainTick = newPreviousGainTick;
109 edm::LogInfo(
"SiStripGainsPCLHarvester") <<
"Starting harvesting statistics" << std::endl;
114 if(stag.size()!=0 && stag[0]!=
'_') stag.insert(0,1,
'_');
120 if (Charge_Vs_Index==0) {
121 edm::LogError(
"SiStripGainsPCLHarvester") <<
"Harvesting: could not retrieve " << cvi.c_str()
122 <<
", statistics will not be summed!" << std::endl;
124 edm::LogInfo(
"SiStripGainsPCLHarvester") <<
"Harvesting " 125 << (Charge_Vs_Index)->getTH2S()->GetEntries() <<
" more clusters" << std::endl;
129 std::unique_ptr<SiStripApvGain> theAPVGains = this->
getNewObject(Charge_Vs_Index);
138 throw std::runtime_error(
"PoolDBService required.");
140 edm::LogInfo(
"SiStripGainsPCLHarvester") <<
"Will not produce payload!" << std::endl;
150 double FitResults[6];
151 double MPVmean = 300;
153 if ( Charge_Vs_Index==0 ) {
154 edm::LogError(
"SiStripGainsPCLHarvester") <<
"Harvesting: could not execute algoComputeMPVandGain method because " 156 <<
"Please check if input contains " 161 TH2S *chvsidx = (Charge_Vs_Index)->getTH2S();
163 printf(
"Progressing Bar :0%% 20%% 40%% 60%% 80%% 100%%\n");
164 printf(
"Fitting Charge Distribution :");
169 if(I%TreeStep==0){printf(
".");fflush(stdout);}
170 std::shared_ptr<stAPVGain>
APV = it->second;
171 if(APV->Bin<0) APV->Bin = chvsidx->GetXaxis()->FindBin(APV->Index);
173 if(APV->isMasked){APV->Gain=APV->PreviousGain;
MASKED++;
continue;}
175 Proj = (TH1F*)(chvsidx->ProjectionY(
"",chvsidx->GetXaxis()->FindBin(APV->Index),chvsidx->GetXaxis()->FindBin(APV->Index),
"e"));
180 int SecondAPVId = APV->APVId;
181 if(SecondAPVId%2==0){ SecondAPVId = SecondAPVId+1; }
else{ SecondAPVId = SecondAPVId-1; }
182 std::shared_ptr<stAPVGain> APV2 =
APVsColl[(APV->DetId<<4) | SecondAPVId];
183 if(APV2->Bin<0) APV2->Bin = chvsidx->GetXaxis()->FindBin(APV2->Index);
184 TH1F* Proj2 = (TH1F*)(chvsidx->ProjectionY(
"",APV2->Bin,APV2->Bin,
"e"));
185 if(Proj2){Proj->Add(Proj2,1);
delete Proj2;}
187 for(
unsigned int i=0;
i<16;
i++){
188 auto tmpit =
APVsColl.find((APV->DetId<<4) |
i);
190 std::shared_ptr<stAPVGain> APV2 = tmpit->second;
191 if(APV2->DetId != APV->DetId || APV2->APVId == APV->APVId)
continue;
192 if(APV2->Bin<0) APV2->Bin = chvsidx->GetXaxis()->FindBin(APV2->Index);
193 TH1F* Proj2 = (TH1F*)(chvsidx->ProjectionY(
"",APV2->Bin,APV2->Bin,
"e"));
194 if(Proj2){Proj->Add(Proj2,1);
delete Proj2;}
202 APV->FitMPV = FitResults[0];
203 APV->FitMPVErr = FitResults[1];
204 APV->FitWidth = FitResults[2];
205 APV->FitWidthErr = FitResults[3];
206 APV->FitChi2 = FitResults[4];
207 APV->FitNorm = FitResults[5];
208 APV->NEntries = Proj->GetEntries();
211 APV->Gain = APV->FitMPV / MPVmean;
212 if(APV->SubDet>2)
GOOD++;
214 APV->Gain = APV->PreviousGain;
215 if(APV->SubDet>2)
BAD++;
217 if(APV->Gain<=0) APV->Gain = 1;
227 FitResults[0] = -0.5;
229 FitResults[2] = -0.5;
231 FitResults[4] = -0.5;
237 TF1 MyLandau(
"MyLandau",
"landau",LowRange, HighRange);
238 MyLandau.SetParameter(1,300);
239 InputHisto->Fit(&MyLandau,
"0QR WW");
242 FitResults[0] = MyLandau.GetParameter(1);
243 FitResults[1] = MyLandau.GetParError(1);
244 FitResults[2] = MyLandau.GetParameter(2);
245 FitResults[3] = MyLandau.GetParError(2);
246 FitResults[4] = MyLandau.GetChisquare() / MyLandau.GetNDF();
247 FitResults[5] = MyLandau.GetParameter(0);
254 if(FitResults[0] <= 0 )
return false;
271 auto const &
Det = newBareTkGeomPtr->
dets();
273 unsigned int Index=0;
275 for(
unsigned int i=0;
i<
Det.size();
i++){
284 if(!DetUnit)
continue;
287 unsigned int NAPV = Topo.
nstrips()/128;
289 for(
unsigned int j=0;j<NAPV;j++){
290 auto APV = std::make_shared<stAPVGain>();
299 APV->FitWidthErr = -1;
303 APV->PreviousGain = 1;
304 APV->PreviousGainTick = 1;
305 APV->x = DetUnit->position().basicVector().x();
306 APV->y = DetUnit->position().basicVector().y();
307 APV->z = DetUnit->position().basicVector().z();
308 APV->Eta = DetUnit->position().basicVector().eta();
309 APV->Phi = DetUnit->position().basicVector().phi();
310 APV->R = DetUnit->position().basicVector().transverse();
311 APV->Thickness = DetUnit->surface().bounds().thickness();
313 APV->isMasked =
false;
323 for(
unsigned int i=0;
i<
Det.size();
i++){
328 if(!DetUnit)
continue;
331 unsigned int NROCRow = Topo.
nrows()/(80.);
332 unsigned int NROCCol = Topo.
ncolumns()/(52.);
334 for(
unsigned int j=0;j<NROCRow;j++){
335 for(
unsigned int i=0;
i<NROCCol;
i++){
336 auto APV = std::make_shared<stAPVGain>();
340 APV->APVId = (j<<3 |
i);
345 APV->FitWidthErr = -1;
348 APV->PreviousGain = 1;
349 APV->PreviousGainTick = 1;
350 APV->x = DetUnit->position().basicVector().x();
351 APV->y = DetUnit->position().basicVector().y();
352 APV->z = DetUnit->position().basicVector().z();
353 APV->Eta = DetUnit->position().basicVector().eta();
354 APV->Phi = DetUnit->position().basicVector().phi();
355 APV->R = DetUnit->position().basicVector().transverse();
356 APV->Thickness = DetUnit->surface().bounds().thickness();
357 APV->isMasked =
false;
379 if( Charge_Vs_Index==0 ) {
380 edm::LogError(
"SiStripGainsPCLHarvester") <<
"produceTagFilter -> Return false: could not retrieve the " 382 <<
"Please check if input contains " 388 float integral = (Charge_Vs_Index)->getTH2S()->Integral();
392 <<
"produceTagFilter -> Return false: Statistics is too low : " << integral << std::endl;
398 <<
"produceTagFilter -> Return false: ratio of GOOD/TOTAL is too low: " << (1.0 *
GOOD) / (
GOOD+
BAD) << std::endl;
405 std::unique_ptr<SiStripApvGain>
408 std::unique_ptr<SiStripApvGain>
obj = std::unique_ptr<SiStripApvGain>(
new SiStripApvGain());
411 edm::LogWarning(
"SiStripGainsPCLHarvester")<<
"getNewObject -> will not produce a paylaod because produceTagFilter returned false " << std::endl;
417 std::vector<float> theSiStripVector;
418 unsigned int PreviousDetId = 0;
421 if(APV==
NULL){ printf(
"Bug\n");
continue; }
422 if(APV->SubDet<=2)
continue;
423 if(APV->DetId != PreviousDetId){
424 if(!theSiStripVector.empty()){
426 if ( !obj->put(PreviousDetId,range) ) printf(
"Bug to put detId = %i\n",PreviousDetId);
428 theSiStripVector.clear();
429 PreviousDetId = APV->DetId;
431 theSiStripVector.push_back(APV->Gain);
433 LogDebug(
"SiStripGainsPCLHarvester")<<
" DetId: "<<APV->DetId
434 <<
" APV: "<<APV->APVId
435 <<
" Gain: "<<APV->Gain
439 if(!theSiStripVector.empty()){
441 if ( !obj->put(PreviousDetId,range) ) printf(
"Bug to put detId = %i\n",PreviousDetId);
std::unique_ptr< SiStripApvGain > getNewObject(const MonitorElement *Charge_Vs_Index)
bool IsApvBad(const uint32_t &detid, const short &apvNb) const
T getUntrackedParameter(std::string const &, T const &) const
virtual int nrows() const =0
virtual void dqmEndJob(DQMStore::IBooker &ibooker_, DQMStore::IGetter &igetter_)
edm::ESHandle< TrackerGeometry > tkGeom_
const DetContainer & dets() const
Returm a vector of all GeomDet (including all GeomDetUnits)
size_t getNumberOfTags() const
MonitorElement * get(const std::string &path)
virtual void beginRun(edm::Run const &run, edm::EventSetup const &isetup)
std::vector< std::string > dqm_tag_
bool produceTagFilter(const MonitorElement *Charge_Vs_Index)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
void getPeakOfLandau(TH1 *InputHisto, double *FitResults, double LowRange=50, double HighRange=5400)
void algoComputeMPVandGain(const MonitorElement *Charge_Vs_Index)
static float getApvGain(const uint16_t &apv, const SiStripApvGain::Range &range)
uint32_t rawId() const
get the raw id
SiStripGainsPCLHarvester(const edm::ParameterSet &ps)
Data available (reporting)
void addDefault(ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
double tagCondition_GoodFrac
std::pair< ContainerIterator, ContainerIterator > Range
const std::complex< double > I
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
virtual void endRun(edm::Run const &run, edm::EventSetup const &isetup)
Integral< F, X >::type integral(const F &f)
std::string m_calibrationMode
bool IsGoodLandauFit(double *FitResults)
virtual int nstrips() const =0
const TrackerGeometry * bareTkGeomPtr_
double tagCondition_NClusters
virtual void checkBookAPVColls(const edm::EventSetup &setup)
std::vector< std::shared_ptr< stAPVGain > > APVsCollOrdered
virtual int ncolumns() const =0
cond::Time_t currentTime() const
const SiStripApvGain::Range getRange(uint32_t detID) const
std::unordered_map< unsigned int, std::shared_ptr< stAPVGain > > APVsColl