94 APV->isMasked = SiStripQuality_->
IsApvBad(APV->DetId,APV->APVId);
97 float newPreviousGain = gainHandle->
getApvGain(APV->APVId,gainHandle->
getRange(APV->DetId, 1),1);
98 if(APV->PreviousGain!=1 and newPreviousGain!=APV->PreviousGain)
edm::LogWarning(
"SiStripGainPCLHarvester")<<
"WARNING: ParticleGain in the global tag changed\n";
99 APV->PreviousGain = newPreviousGain;
101 float newPreviousGainTick = gainHandle->
getApvGain(APV->APVId,gainHandle->
getRange(APV->DetId, 0),0);
102 if(APV->PreviousGainTick!=1 and newPreviousGainTick!=APV->PreviousGainTick){
103 edm::LogWarning(
"SiStripGainPCLHarvester")<<
"WARNING: TickMarkGain in the global tag changed\n"<< std::endl
104 <<
" APV->SubDet: "<< APV->SubDet <<
" APV->APVId:" << APV->APVId << std::endl
105 <<
" APV->PreviousGainTick: "<<APV->PreviousGainTick<<
" newPreviousGainTick: "<<newPreviousGainTick<<std::endl;
107 APV->PreviousGainTick = newPreviousGainTick;
114 edm::LogInfo(
"SiStripGainsPCLHarvester") <<
"Starting harvesting statistics" << std::endl;
119 if(!stag.empty() && stag[0]!=
'_') stag.insert(0,1,
'_');
125 if (Charge_Vs_Index==
nullptr) {
126 edm::LogError(
"SiStripGainsPCLHarvester") <<
"Harvesting: could not retrieve " << cvi.c_str()
127 <<
", statistics will not be summed!" << std::endl;
129 edm::LogInfo(
"SiStripGainsPCLHarvester") <<
"Harvesting " 130 << (Charge_Vs_Index)->getTH2S()->GetEntries() <<
" more clusters" << std::endl;
134 std::unique_ptr<SiStripApvGain> theAPVGains = this->
getNewObject(Charge_Vs_Index);
143 throw std::runtime_error(
"PoolDBService required.");
145 edm::LogInfo(
"SiStripGainsPCLHarvester") <<
"Will not produce payload!" << std::endl;
160 std::vector<APVGain::APVmon> new_charge_histos;
162 for (
unsigned int i=0;
i<cnames.size();
i++){
174 MonitorElement* MPV_Vs_EtaTIB = ibooker_.
book2DD(
"MPVvsEtaTIB" ,
"MPV vs Eta TIB" ,50,-3.0,3.0,MPVbin,MPVmin,MPVmax);
175 MonitorElement* MPV_Vs_EtaTID = ibooker_.
book2DD(
"MPVvsEtaTID" ,
"MPV vs Eta TID" ,50,-3.0,3.0,MPVbin,MPVmin,MPVmax);
176 MonitorElement* MPV_Vs_EtaTOB = ibooker_.
book2DD(
"MPVvsEtaTOB" ,
"MPV vs Eta TOB" ,50,-3.0,3.0,MPVbin,MPVmin,MPVmax);
177 MonitorElement* MPV_Vs_EtaTEC = ibooker_.
book2DD(
"MPVvsEtaTEC" ,
"MPV vs Eta TEC" ,50,-3.0,3.0,MPVbin,MPVmin,MPVmax);
178 MonitorElement* MPV_Vs_EtaTECthin = ibooker_.
book2DD(
"MPVvsEtaTEC1",
"MPV vs Eta TEC-thin" ,50,-3.0,3.0,MPVbin,MPVmin,MPVmax);
179 MonitorElement* MPV_Vs_EtaTECthick = ibooker_.
book2DD(
"MPVvsEtaTEC2",
"MPV vs Eta TEC-thick",50,-3.0,3.0,MPVbin,MPVmin,MPVmax);
181 MonitorElement* MPV_Vs_PhiTIB = ibooker_.
book2DD(
"MPVvsPhiTIB" ,
"MPV vs Phi TIB" ,50,-3.4,3.4,MPVbin,MPVmin,MPVmax);
182 MonitorElement* MPV_Vs_PhiTID = ibooker_.
book2DD(
"MPVvsPhiTID" ,
"MPV vs Phi TID" ,50,-3.4,3.4,MPVbin,MPVmin,MPVmax);
183 MonitorElement* MPV_Vs_PhiTOB = ibooker_.
book2DD(
"MPVvsPhiTOB" ,
"MPV vs Phi TOB" ,50,-3.4,3.4,MPVbin,MPVmin,MPVmax);
184 MonitorElement* MPV_Vs_PhiTEC = ibooker_.
book2DD(
"MPVvsPhiTEC" ,
"MPV vs Phi TEC" ,50,-3.4,3.4,MPVbin,MPVmin,MPVmax);
185 MonitorElement* MPV_Vs_PhiTECthin = ibooker_.
book2DD(
"MPVvsPhiTEC1",
"MPV vs Phi TEC-thin ",50,-3.4,3.4,MPVbin,MPVmin,MPVmax);
186 MonitorElement* MPV_Vs_PhiTECthick = ibooker_.
book2DD(
"MPVvsPhiTEC2",
"MPV vs Phi TEC-thick",50,-3.4,3.4,MPVbin,MPVmin,MPVmax);
188 MonitorElement* NoMPVfit = ibooker_.
book2DD(
"NoMPVfit" ,
"Modules with bad Landau Fit",350, -350, 350, 240, 0, 120);
189 MonitorElement* NoMPVmasked = ibooker_.
book2DD(
"NoMPVmasked" ,
"Masked Modules" ,350, -350, 350, 240, 0, 120);
211 MonitorElement* MPVErrorVsMPV = ibooker_.
book2DD(
"MPVErrorVsMPV" ,
"MPV Error vs MPV" , 300, 0, 600, 150, 0, 150);
212 MonitorElement* MPVErrorVsEta = ibooker_.
book2DD(
"MPVErrorVsEta" ,
"MPV Error vs Eta" , 50, -3.0, 3.0, 150, 0, 150);
213 MonitorElement* MPVErrorVsPhi = ibooker_.
book2DD(
"MPVErrorVsPhi" ,
"MPV Error vs Phi" , 50, -3.4, 3.4, 150, 0, 150);
214 MonitorElement* MPVErrorVsN = ibooker_.
book2DD(
"MPVErrorVsN" ,
"MPV Error vs N" , 500, 0, 1000, 150, 0, 150);
216 MonitorElement* DiffWRTPrevGainTIB = ibooker_.
book1DD(
"DiffWRTPrevGainTIB" ,
"Diff w.r.t. PrevGain TIB" , 250, 0,2);
217 MonitorElement* DiffWRTPrevGainTID = ibooker_.
book1DD(
"DiffWRTPrevGainTID" ,
"Diff w.r.t. PrevGain TID" , 250, 0,2);
218 MonitorElement* DiffWRTPrevGainTOB = ibooker_.
book1DD(
"DiffWRTPrevGainTOB" ,
"Diff w.r.t. PrevGain TOB" , 250, 0,2);
219 MonitorElement* DiffWRTPrevGainTEC = ibooker_.
book1DD(
"DiffWRTPrevGainTEC" ,
"Diff w.r.t. PrevGain TEC" , 250, 0,2);
221 MonitorElement* GainVsPrevGainTIB = ibooker_.
book2DD(
"GainVsPrevGainTIB" ,
"Gain vs PrevGain TIB" , 100, 0,2, 100, 0,2);
222 MonitorElement* GainVsPrevGainTID = ibooker_.
book2DD(
"GainVsPrevGainTID" ,
"Gain vs PrevGain TID" , 100, 0,2, 100, 0,2);
223 MonitorElement* GainVsPrevGainTOB = ibooker_.
book2DD(
"GainVsPrevGainTOB" ,
"Gain vs PrevGain TOB" , 100, 0,2, 100, 0,2);
224 MonitorElement* GainVsPrevGainTEC = ibooker_.
book2DD(
"GainVsPrevGainTEC" ,
"Gain vs PrevGain TEC" , 100, 0,2, 100, 0,2);
230 if(APV==
nullptr)
continue;
232 unsigned int Index = APV->Index;
233 unsigned int SubDet = APV->SubDet;
236 float Eta = APV->Eta;
238 float Phi = APV->Phi;
239 float Thickness = APV->Thickness;
240 double FitMPV = APV->FitMPV;
241 double FitMPVErr = APV->FitMPVErr;
242 double Gain = APV->Gain;
243 double NEntries = APV->NEntries;
244 double PreviousGain = APV->PreviousGain;
246 if (SubDet<3)
continue;
250 TH2S *chvsidx = (Charge_Vs_Index)->getTH2S();
251 int bin = chvsidx->GetXaxis()->FindBin(Index);
252 TH1D* Proj = chvsidx->ProjectionY(
"proj",bin,bin);
253 for (
int binId=0; binId<Proj->GetXaxis()->GetNbins();binId++) {
254 double new_charge = Proj->GetXaxis()->GetBinCenter(binId) /
Gain;
255 if (Proj->GetBinContent(binId)!=0.) {
256 for (
unsigned int h=0;
h<charge_histos.size();
h++) {
257 TH1D* chisto = (charge_histos[
h])->getTH1D();
258 for (
int e=0;
e<Proj->GetBinContent(binId);
e++) chisto->Fill(new_charge);
266 if (APV->isMasked) NoMPVmasked->
Fill(z,R);
267 else NoMPVfit->
Fill(z,R);
270 if(FitMPV>0.) Gains->
Fill(Gain);
273 if(Thickness<0.04) MPVs320->
Fill(FitMPV);
274 if(Thickness>0.04) MPVs500->
Fill(FitMPV);
276 MPVError->
Fill(FitMPVErr);
277 MPVErrorVsMPV->
Fill(FitMPV,FitMPVErr);
278 MPVErrorVsEta->
Fill(Eta,FitMPVErr);
279 MPVErrorVsPhi->
Fill(Phi,FitMPVErr);
280 MPVErrorVsN->
Fill(NEntries,FitMPVErr);
283 MPV_Vs_EtaTIB->
Fill(Eta,FitMPV);
284 MPV_Vs_PhiTIB->
Fill(Phi,FitMPV);
285 MPVsTIB->
Fill(FitMPV);
287 }
else if(SubDet==4) {
288 MPV_Vs_EtaTID->
Fill(Eta,FitMPV);
289 MPV_Vs_PhiTID->
Fill(Phi,FitMPV);
290 MPVsTID->
Fill(FitMPV);
291 if(Eta<0.) MPVsTIDM->
Fill(FitMPV);
292 if(Eta>0.) MPVsTIDP->
Fill(FitMPV);
294 }
else if (SubDet==5) {
295 MPV_Vs_EtaTOB->
Fill(Eta,FitMPV);
296 MPV_Vs_PhiTOB->
Fill(Phi,FitMPV);
297 MPVsTOB->
Fill(FitMPV);
299 }
else if (SubDet==6) {
300 MPV_Vs_EtaTEC->
Fill(Eta,FitMPV);
301 MPV_Vs_PhiTEC->
Fill(Phi,FitMPV);
302 MPVsTEC->
Fill(FitMPV);
303 if(Eta<0.) MPVsTECM->
Fill(FitMPV);
304 if(Eta>0.) MPVsTECP->
Fill(FitMPV);
306 MPV_Vs_EtaTECthin->
Fill(Eta,FitMPV);
307 MPV_Vs_PhiTECthin->
Fill(Phi,FitMPV);
308 MPVsTECthin->
Fill(FitMPV);
309 if(Eta>0.) MPVsTECP1->
Fill(FitMPV);
310 if(Eta<0.) MPVsTECM1->
Fill(FitMPV);
313 MPV_Vs_EtaTECthick->
Fill(Eta,FitMPV);
314 MPV_Vs_PhiTECthick->
Fill(Phi,FitMPV);
315 MPVsTECthick->
Fill(FitMPV);
316 if(Eta>0.) MPVsTECP2->
Fill(FitMPV);
317 if(Eta<0.) MPVsTECM2->
Fill(FitMPV);
322 if(SubDet==3 && PreviousGain!=0. ) DiffWRTPrevGainTIB->
Fill(Gain/PreviousGain);
323 else if(SubDet==4 && PreviousGain!=0. ) DiffWRTPrevGainTID->
Fill(Gain/PreviousGain);
324 else if(SubDet==5 && PreviousGain!=0. ) DiffWRTPrevGainTOB->
Fill(Gain/PreviousGain);
325 else if(SubDet==6 && PreviousGain!=0. ) DiffWRTPrevGainTEC->
Fill(Gain/PreviousGain);
327 if(SubDet==3 ) GainVsPrevGainTIB->
Fill(PreviousGain,Gain);
328 else if(SubDet==4 ) GainVsPrevGainTID->
Fill(PreviousGain,Gain);
329 else if(SubDet==5 ) GainVsPrevGainTOB->
Fill(PreviousGain,Gain);
330 else if(SubDet==6 ) GainVsPrevGainTEC->
Fill(PreviousGain,Gain);
341 TH1F* Proj =
nullptr;
342 double FitResults[6];
343 double MPVmean = 300;
345 if ( Charge_Vs_Index==
nullptr ) {
346 edm::LogError(
"SiStripGainsPCLHarvester") <<
"Harvesting: could not execute algoComputeMPVandGain method because " 348 <<
"Please check if input contains " 353 TH2S *chvsidx = (Charge_Vs_Index)->getTH2S();
355 printf(
"Progressing Bar :0%% 20%% 40%% 60%% 80%% 100%%\n");
356 printf(
"Fitting Charge Distribution :");
361 if(I%TreeStep==0){printf(
".");fflush(
stdout);}
362 std::shared_ptr<stAPVGain>
APV = it->second;
363 if(APV->Bin<0) APV->Bin = chvsidx->GetXaxis()->FindBin(APV->Index);
365 if(APV->isMasked){APV->Gain=APV->PreviousGain;
MASKED++;
continue;}
367 Proj = (TH1F*)(chvsidx->ProjectionY(
"",chvsidx->GetXaxis()->FindBin(APV->Index),chvsidx->GetXaxis()->FindBin(APV->Index),
"e"));
372 int SecondAPVId = APV->APVId;
373 if(SecondAPVId%2==0){ SecondAPVId = SecondAPVId+1; }
else{ SecondAPVId = SecondAPVId-1; }
374 std::shared_ptr<stAPVGain> APV2 =
APVsColl[(APV->DetId<<4) | SecondAPVId];
375 if(APV2->Bin<0) APV2->Bin = chvsidx->GetXaxis()->FindBin(APV2->Index);
376 TH1F* Proj2 = (TH1F*)(chvsidx->ProjectionY(
"",APV2->Bin,APV2->Bin,
"e"));
377 if(Proj2){Proj->Add(Proj2,1);
delete Proj2;}
379 for(
unsigned int i=0;
i<16;
i++){
380 auto tmpit =
APVsColl.find((APV->DetId<<4) |
i);
382 std::shared_ptr<stAPVGain> APV2 = tmpit->second;
383 if(APV2->DetId != APV->DetId || APV2->APVId == APV->APVId)
continue;
384 if(APV2->Bin<0) APV2->Bin = chvsidx->GetXaxis()->FindBin(APV2->Index);
385 TH1F* Proj2 = (TH1F*)(chvsidx->ProjectionY(
"",APV2->Bin,APV2->Bin,
"e"));
386 if(Proj2){Proj->Add(Proj2,1);
delete Proj2;}
394 APV->FitMPV = FitResults[0];
395 APV->FitMPVErr = FitResults[1];
396 APV->FitWidth = FitResults[2];
397 APV->FitWidthErr = FitResults[3];
398 APV->FitChi2 = FitResults[4];
399 APV->FitNorm = FitResults[5];
400 APV->NEntries = Proj->GetEntries();
403 APV->Gain = APV->FitMPV / MPVmean;
404 if(APV->SubDet>2)
GOOD++;
406 APV->Gain = APV->PreviousGain;
407 if(APV->SubDet>2)
BAD++;
409 if(APV->Gain<=0) APV->Gain = 1;
419 FitResults[0] = -0.5;
421 FitResults[2] = -0.5;
423 FitResults[4] = -0.5;
429 TF1 MyLandau(
"MyLandau",
"landau",LowRange, HighRange);
430 MyLandau.SetParameter(1,300);
431 InputHisto->Fit(&MyLandau,
"0QR WW");
434 FitResults[0] = MyLandau.GetParameter(1);
435 FitResults[1] = MyLandau.GetParError(1);
436 FitResults[2] = MyLandau.GetParameter(2);
437 FitResults[3] = MyLandau.GetParError(2);
438 FitResults[4] = MyLandau.GetChisquare() / MyLandau.GetNDF();
439 FitResults[5] = MyLandau.GetParameter(0);
446 if(FitResults[0] <= 0 )
return false;
463 auto const &
Det = newBareTkGeomPtr->
dets();
465 unsigned int Index=0;
467 for(
unsigned int i=0;
i<
Det.size();
i++){
476 if(!DetUnit)
continue;
479 unsigned int NAPV = Topo.
nstrips()/128;
481 for(
unsigned int j=0;j<NAPV;j++){
482 auto APV = std::make_shared<stAPVGain>();
491 APV->FitWidthErr = -1;
495 APV->PreviousGain = 1;
496 APV->PreviousGainTick = 1;
497 APV->x = DetUnit->position().basicVector().x();
498 APV->y = DetUnit->position().basicVector().y();
499 APV->z = DetUnit->position().basicVector().z();
500 APV->Eta = DetUnit->position().basicVector().eta();
501 APV->Phi = DetUnit->position().basicVector().phi();
502 APV->R = DetUnit->position().basicVector().transverse();
503 APV->Thickness = DetUnit->surface().bounds().thickness();
505 APV->isMasked =
false;
515 for(
unsigned int i=0;
i<
Det.size();
i++){
520 if(!DetUnit)
continue;
523 unsigned int NROCRow = Topo.
nrows()/(80.);
524 unsigned int NROCCol = Topo.
ncolumns()/(52.);
526 for(
unsigned int j=0;j<NROCRow;j++){
527 for(
unsigned int i=0;
i<NROCCol;
i++){
528 auto APV = std::make_shared<stAPVGain>();
532 APV->APVId = (j<<3 |
i);
537 APV->FitWidthErr = -1;
540 APV->PreviousGain = 1;
541 APV->PreviousGainTick = 1;
542 APV->x = DetUnit->position().basicVector().x();
543 APV->y = DetUnit->position().basicVector().y();
544 APV->z = DetUnit->position().basicVector().z();
545 APV->Eta = DetUnit->position().basicVector().eta();
546 APV->Phi = DetUnit->position().basicVector().phi();
547 APV->R = DetUnit->position().basicVector().transverse();
548 APV->Thickness = DetUnit->surface().bounds().thickness();
549 APV->isMasked =
false;
580 if( Charge_Vs_Index==
nullptr ) {
581 edm::LogError(
"SiStripGainsPCLHarvester") <<
"produceTagFilter -> Return false: could not retrieve the " 583 <<
"Please check if input contains " 589 float integral = (Charge_Vs_Index)->getTH2S()->Integral();
593 <<
"produceTagFilter -> Return false: Statistics is too low : " << integral << std::endl;
599 <<
"produceTagFilter -> Return false: ratio of GOOD/TOTAL is too low: " << (1.0 *
GOOD) / (
GOOD+
BAD) << std::endl;
606 std::unique_ptr<SiStripApvGain>
609 std::unique_ptr<SiStripApvGain>
obj = std::unique_ptr<SiStripApvGain>(
new SiStripApvGain());
612 edm::LogWarning(
"SiStripGainsPCLHarvester")<<
"getNewObject -> will not produce a paylaod because produceTagFilter returned false " << std::endl;
618 std::vector<float> theSiStripVector;
619 unsigned int PreviousDetId = 0;
622 if(APV==
nullptr){ printf(
"Bug\n");
continue; }
623 if(APV->SubDet<=2)
continue;
624 if(APV->DetId != PreviousDetId){
625 if(!theSiStripVector.empty()){
627 if ( !obj->put(PreviousDetId,range) ) printf(
"Bug to put detId = %i\n",PreviousDetId);
629 theSiStripVector.clear();
630 PreviousDetId = APV->DetId;
632 theSiStripVector.push_back(APV->Gain);
634 LogDebug(
"SiStripGainsPCLHarvester")<<
" DetId: "<<APV->DetId
635 <<
" APV: "<<APV->APVId
636 <<
" Gain: "<<APV->Gain
640 if(!theSiStripVector.empty()){
642 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
edm::ESHandle< TrackerGeometry > tkGeom_
void dqmEndJob(DQMStore::IBooker &ibooker_, DQMStore::IGetter &igetter_) override
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
size_t getNumberOfTags() const
MonitorElement * get(const std::string &path)
constexpr uint32_t rawId() const
get the raw id
const TrackerTopology * tTopo_
int subdetectorPlane(uint32_t, const TrackerTopology *)
def setup(process, global_tag, zero_tesla=False)
std::vector< std::string > dqm_tag_
void beginRun(edm::Run const &run, edm::EventSetup const &isetup) override
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)
U second(std::pair< T, U > const &p)
SiStripGainsPCLHarvester(const edm::ParameterSet &ps)
std::vector< MonitorElement * > FetchMonitor(std::vector< APVmon >, uint32_t, const TrackerTopology *topo=0)
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
Data available (reporting)
void addDefault(ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
double tagCondition_GoodFrac
bool doChargeMonitorPerPlane
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
std::pair< ContainerIterator, ContainerIterator > Range
const std::complex< double > I
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
std::vector< std::string > VChargeHisto
Integral< F, X >::type integral(const F &f)
bin
set the eta bin as selection string.
virtual void checkAndRetrieveTopology(const edm::EventSetup &setup)
std::string m_calibrationMode
bool IsGoodLandauFit(double *FitResults)
void setCurrentFolder(const std::string &fullpath)
void gainQualityMonitor(DQMStore::IBooker &ibooker_, const MonitorElement *Charge_Vs_Index) const
virtual int nstrips() const =0
int subdetectorSide(uint32_t, const TrackerTopology *)
const TrackerGeometry * bareTkGeomPtr_
void endRun(edm::Run const &run, edm::EventSetup const &isetup) override
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
MonitorElement * book2DD(Args &&...args)
std::vector< std::pair< std::string, std::string > > monHnames(std::vector< std::string >, bool, const char *tag)
MonitorElement * book1DD(Args &&...args)
T const * product() const
int subdetectorId(uint32_t)
constexpr DetId()
Create an empty or null id (also for persistence)
const SiStripApvGain::Range getRange(uint32_t detID) const
std::unordered_map< unsigned int, std::shared_ptr< stAPVGain > > APVsColl